【发布时间】:2009-09-16 06:00:20
【问题描述】:
我们如何在 RichTextField 中设置背景和字体颜色?除了here 描述的内容之外,我还尝试覆盖paint() 方法,但是当我向下滚动时,背景会被擦除或重置为白色背景
【问题讨论】:
标签: user-interface blackberry layout colors
我们如何在 RichTextField 中设置背景和字体颜色?除了here 描述的内容之外,我还尝试覆盖paint() 方法,但是当我向下滚动时,背景会被擦除或重置为白色背景
【问题讨论】:
标签: user-interface blackberry layout colors
在 RIM 4.6 及更高版本中,您可以使用背景:
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 及更低版本,请使用绘画事件自己绘制背景:
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 mes_=new RichTextField("texto de ejemplo",Field.NON_FOCUSABLE){
protected void paint(Graphics g){
g.setColor(0x00e52f64);
super.paint(g);
}
};
mes_.setBackground(BackgroundFactory.createSolidBackground(0xFFFADDDA));
声明中包含的用于更改字体颜色的方法。在创建后调用的方法将背景更改为纯色。
【讨论】: