Setting background and font colors for RichTextField, TextField

后端 未结 2 2033
暖寄归人
暖寄归人 2020-12-21 17:13

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 i

相关标签:
2条回答
  • 2020-12-21 17:20

    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);
        }
    }
    
    0 讨论(0)
  • 2020-12-21 17:20
    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.

    0 讨论(0)
提交回复
热议问题