BlackBerry RichText格式化
我正在使用 BlackBerry 知识中心教程“如何设置 RichTextField 格式" 为我的 RichTextField 设置格式。
我在格式化文本时遇到了一些困难,例如:
AI在B街上行走突然看到一只会飞的狗
如果我只想加粗字母A和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
}
I am using the BlackBerry knowledge center tutorial "How To Format RichTextField" to set a format for my RichTextField.
I encountered some difficulty when formatting text like:
A I was walking in the street B suddenly I saw a flying dog
If I want to bold only the letters A & B I need to have their string indexes and length.
I created 2 arrays, one handles the indexes of the letters in the entire text and the second array handles the length of each letter index, for example: A (length 1), WC(length 2).
I tried to run it in a loop but it doesn't work:
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
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
抱歉,没有更好的代码,但希望它有所帮助。
Sorry not nicer code, but hope it helps.