0

私はBlackBerryナレッジセンターのチュートリアル「RichTextFieldをフォーマットする方法」を使用してRichTextFieldのフォーマットを設定しています。

次のようなテキストをフォーマットするときに、いくつかの問題が発生しました。

AIが通りを歩いていたB突然飛んでいる犬を見た

AとBIの文字だけを太字にする場合は、文字列のインデックスと長さを指定する必要があります。

2つの配列を作成しました。1つはテキスト全体の文字のインデックスを処理し、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
    }
4

1 に答える 1

0
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

申し訳ありませんが、コードは良くありませんが、お役に立てば幸いです。

于 2011-07-04T16:48:28.080 に答える