【问题标题】:Setting background and font colors for RichTextField, TextField为 RichTextField、TextField 设置背景和字体颜色
【发布时间】:2009-09-16 06:00:20
【问题描述】:

我们如何在 RichTextField 中设置背景和字体颜色?除了here 描述的内容之外,我还尝试覆盖paint() 方法,但是当我向下滚动时,背景会被擦除或重置为白色背景

【问题讨论】:

    标签: user-interface blackberry layout colors


    【解决方案1】:

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

    【讨论】:

    • 谢谢,轻而易举!但是,当我将它添加到 VerticalFieldManager 时,我看不到滚动条,我已将 Manager 的样式设置为 VERTICAL_SCROLL } VERTICAL_SCROLLBAR。没有出现的原因有哪些?
    • 无法解决这个问题.. 设置管理器的首选大小时似乎不会出现滚动条。
    • 我遇到的另一个问题是,当我在 BitmapField 之后将 ExRichTextField 添加到 VerticalFieldManager 时,整个屏幕滚动而不是 ExRichTextField 单独滚动,这是预期的行为。向班级添加两名经理会解决问题吗?
    • 嗨拉姆!似乎没有显示标准滚动条的解决方法,所以我只是自定义绘制。见更新stackoverflow.com/questions/1426081/…
    【解决方案2】:
    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));
    

    声明中包含的用于更改字体颜色的方法。在创建后调用的方法将背景更改为纯色。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-08
      • 2011-11-07
      • 1970-01-01
      • 2010-09-16
      • 2013-04-02
      • 1970-01-01
      • 2010-11-08
      • 2020-12-06
      相关资源
      最近更新 更多