Prabhu R
Prabhu R

Reputation: 14242

Setting background and font colors for RichTextField, TextField

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

Upvotes: 3

Views: 4591

Answers (2)

jmlv21104
jmlv21104

Reputation: 89

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));

The method incrustaded in the declaration its for changing the color of the font. The method called after created its for changing the background to a solid color.

Upvotes: 0

Maksym Gontar
Maksym Gontar

Reputation: 22775

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);
    }
}

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);
    }
}

Upvotes: 4

Related Questions