黑莓:RichTextField 的问题
我想在屏幕上添加一些文本。由于此文本会根据单词改变颜色,因此我决定使用 RichTextField
。 这是我的代码:
String productName = product.getProductName()+": ";
String price = String.valueOf(product.getPrice());
Font[] fonts = new Font[2];
fonts[0] = Font.getDefault().derive(Font.PLAIN, 12);
fonts[1] = fonts[0].derive(Font.BOLD);
byte[] attribs = new byte[] {0, 1};
int[] offsets = new int[] {0, productName.length(), productName.length() + price.length()};
int[] fontColors = new int[] {Color.BLACK, Color.GREEN};
int[] backColors = new int[] {Color.WHITE, Color.WHITE};
RichTextField labelPrice = new RichTextField(productName + price, offsets, attribs, fonts, Field.FIELD_LEFT|FIELD_VCENTER);
labelPrice.setAttributes(fontColors, backColors);
我可以添加文本,除了背景之外没有问题。我的product
的第一个字母有蓝色背景,我没有在其他地方添加任何蓝色,即使我是,我也希望它会被backColors
覆盖。有谁知道为什么会发生这种情况?
提前致谢!
编辑:我只是在这里修复 raukodraug 为像我这样的新手指出的代码
RichTextField labelPrice = new RichTextField(productName + price, offsets, attribs, fonts, Field.FIELD_LEFT|FIELD_VCENTER|Field.NON_FOCUSABLE);
I want to add some text to a screen. Since this text changes color according to the words I decided to use a RichTextField
.
Here is my code:
String productName = product.getProductName()+": ";
String price = String.valueOf(product.getPrice());
Font[] fonts = new Font[2];
fonts[0] = Font.getDefault().derive(Font.PLAIN, 12);
fonts[1] = fonts[0].derive(Font.BOLD);
byte[] attribs = new byte[] {0, 1};
int[] offsets = new int[] {0, productName.length(), productName.length() + price.length()};
int[] fontColors = new int[] {Color.BLACK, Color.GREEN};
int[] backColors = new int[] {Color.WHITE, Color.WHITE};
RichTextField labelPrice = new RichTextField(productName + price, offsets, attribs, fonts, Field.FIELD_LEFT|FIELD_VCENTER);
labelPrice.setAttributes(fontColors, backColors);
I can add the text and there is no problem but the background. The first letter of my product
has a blue background, im not adding any blue anywhere else, and even if i was, i would expect that it would be overriden with backColors
. Does anyone know why this is happening?
Thanks in advance!
EDIT: I'm just fixing the code here that raukodraug pointed out for rookies like me
RichTextField labelPrice = new RichTextField(productName + price, offsets, attribs, fonts, Field.FIELD_LEFT|FIELD_VCENTER|Field.NON_FOCUSABLE);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我认为你的问题不在于它有蓝色背景,而在于它的焦点。尝试移动拨轮,您就会看到。
您应该将
Field.NON_FOCUSABLE
添加到RichTextField
样式中。我很确定这会解决你的问题。正如您在此处看到的 你应该这样做,这样它就无法接受焦点。
我希望这有帮助
Well, I think your problem is not that it has a blue background but that it is focused. Try to move the trackwheel and you will see.
You should add
Field.NON_FOCUSABLE
to theRichTextField
styles. I'm pretty sure that will fix your problem.As you can see here you should do this so it cannot accept focus.
I hope this helps