开发者

Blackberry: problem with RichTextField

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 the开发者_开发技巧re 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);


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 the RichTextField 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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜