2011-03-15 145 views
1

我想添加一些文字到屏幕上。由于此文字根据我决定使用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); 

回答

0

嗯,我觉得你的问题不在于它有一个蓝色的背景但它很专注。试着移动拨轮,你会看到。 您应该将Field.NON_FOCUSABLE添加到RichTextField样式中。我很确定这会解决你的问题。 正如你所看到的here你应该这样做,所以它不能接受焦点。 我希望这可以帮助

+1

噢,那是菜鸟的错误,非常感谢您的帮助raukodraug。 – chekemp 2011-03-15 15:54:17

+0

@chekemp np,我希望它帮助:) – raukodraug 2011-03-15 15:58:35