本文介绍了设置RichTextField,TextField的背景和字体颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们如何在RichTextField中设置背景和字体颜色?我试图覆盖paint()方法,除了已经描述的,但当我向下滚动时,背景会被擦除或重置为白色背景。

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

推荐答案

你可以使用背景:

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事件绘制背景

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,TextField的背景和字体颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 09:44