设置背景和字体颜色RichTextField,文本字段 [英] Setting background and font colors for RichTextField, TextField
本文介绍了设置背景和字体颜色RichTextField,文本字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们如何设置在RichTextField的背景和字体颜色?我试图覆盖除了已经描述的涂料()方法<一href=\"http://stackoverflow.com/questions/1426081/creating-custom-layouts-in-blackberry/1428106#1428106\">here,但是当我在向下滚动时,背景被擦除或重置为白色背景
How do we set the background and font colors in a RichTextField? I tried to override the paint() method in addition to what has been described here, but when I scroll down in, the background gets erased or reset to a white background
推荐答案
在RIM 4.6和更大的可使用背景:
In RIM 4.6 and greater you can use Background:
class ExRichTextField extends RichTextField {
int mTextColor;
public ExRichTextField(String text, int bgColor, int textColor) {
super(text);
mTextColor = textColor;
Background background = BackgroundFactory
.createSolidBackground(bgColor);
setBackground(background);
}
protected void paint(Graphics graphics) {
graphics.setColor(mTextColor);
super.paint(graphics);
}
}
有关RIM 4.5和更低的使用Paint事件来绘制背景youreself:
For RIM 4.5 and lower use paint event to draw background youreself:
class ExRichTextField extends RichTextField {
int mTextColor;
int mBgColor;
public ExRichTextField(String text, int bgColor, int textColor) {
super(text);
mTextColor = textColor;
mBgColor = bgColor;
}
protected void paint(Graphics graphics) {
graphics.clear();
graphics.setColor(mBgColor);
graphics.fillRect(0, 0, getWidth(), getHeight());
graphics.setColor(mTextColor);
super.paint(graphics);
}
}
这篇关于设置背景和字体颜色RichTextField,文本字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文