BlackBerry RichTextFormatting - PullRequest
       11

BlackBerry RichTextFormatting

0 голосов
/ 20 мая 2011

Я использую учебное пособие BlackBerry для центра знаний " Как отформатировать RichTextField ", чтобы установить формат для моего RichTextField.

Я столкнулся с некоторыми трудностями при форматировании текста, например:

A я шел по улице B вдруг увидел летающую собаку

Если я хочу выделить только буквы A и B, мне нужно иметь их строковые индексы и длину.

Я создал 2 массива: один обрабатывает индексы букв во всем тексте, а второй - длину каждого буквенного индекса, например: A (длина 1), WC (длина 2).

Я пытался запустить его в цикле, но он не работает:

Font fonts[] = new Font[2];
    int[] offset = new int[3];
    byte[] attribute = new byte[3];

    //Get three instances of the default font.
    //On plain, one bold and one bold and italic.
    fonts[0] = Font.getDefault();
    fonts[1] = Font.getDefault().derive(Font.BOLD);

    for (int i = 0; i<lettersLength; i++) {
      offset[0] = letterIndexes[i]; //handles the indexes of the letters in the entire text
      attribute[0] = 1;
      offset[1] = letterLength[i]; //handles each letter index
    }

1 Ответ

0 голосов
/ 04 июля 2011
offsets[0] = 0; // index of A, first character
attribute[0] = 1;  // Choose the bold font starting at offsets[0]
offsets[1] = 1;  // 1 past the desired bold
attributes[1] = 0;  // assign the regular font starting at offset[1]
offsets[2] = index of 'B';
attributes[2] = 1; // set the style to the bold font for this
offsets[3] = index of 'B' + 1; // the new non bold segment starts just after the B
attributes[3] = 0; // set the style to normal

Извините, не хороший код, но надеюсь, что это поможет.

...