我正在使用 BlackBerry 知识中心教程“如何格式化 RichTextField ”为我的 RichTextField 设置格式。
我在格式化文本时遇到了一些困难,例如:
AI 走在街上 B 突然看到一只会飞的狗
如果我只想加粗字母 A 和 BI 需要有它们的字符串索引和长度。
我创建了 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
}