2011-03-15 152 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