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);
噢,那是菜鳥的錯誤,非常感謝您的幫助raukodraug。 – chekemp 2011-03-15 15:54:17
@chekemp np,我希望它幫助:) – raukodraug 2011-03-15 15:58:35