【问题标题】:How to change the font color of blackberry label field dynamically?如何动态更改黑莓标签字段的字体颜色?
【发布时间】:2009-09-02 07:25:38
【问题描述】:

我有一个标签字段和三个按钮,名称分别为红色、黄色、蓝色。如果我单击红色按钮,则标签字段字体颜色应更改为红色;同样,如果我单击黄色按钮,则字体颜色应变为黄色;同样根据按钮颜色,标签字段中的字体颜色应该改变。

谁能告诉我怎么做?

【问题讨论】:

    标签: user-interface blackberry


    【解决方案1】:

    LabelField 中的字体颜色可以通过在 super.paint 之前的绘制事件上设置 graphics.setColor 来轻松维护:

        class FCLabelField extends LabelField {
            public FCLabelField(Object text, long style) {
                super(text, style);
            }
    
            private int mFontColor = -1;
    
            public void setFontColor(int fontColor) {
                mFontColor = fontColor;
            }
    
            protected void paint(Graphics graphics) {
                if (-1 != mFontColor)
                    graphics.setColor(mFontColor);
                super.paint(graphics);
            }
        }
    
        class Scr extends MainScreen implements FieldChangeListener {
            FCLabelField mLabel;
            ButtonField mRedButton;
            ButtonField mGreenButton;
            ButtonField mBlueButton;
    
            public Scr() {
                mLabel = new FCLabelField("COLOR LABEL", 
                        FIELD_HCENTER);
                add(mLabel);
                mRedButton = new ButtonField("RED", 
                        ButtonField.CONSUME_CLICK|FIELD_HCENTER);
                mRedButton.setChangeListener(this);
                add(mRedButton);
                mGreenButton = new ButtonField("GREEN", 
                        ButtonField.CONSUME_CLICK|FIELD_HCENTER);
                mGreenButton.setChangeListener(this);
                add(mGreenButton);
                mBlueButton = new ButtonField("BLUE", 
                        ButtonField.CONSUME_CLICK|FIELD_HCENTER);
                mBlueButton.setChangeListener(this);
                add(mBlueButton);
            }
    
            public void fieldChanged(Field field, int context) {
                if (field == mRedButton) {
                    mLabel.setFontColor(Color.RED);
                } else if (field == mGreenButton) {
                    mLabel.setFontColor(Color.GREEN);
                } else if (field == mBlueButton) {
                    mLabel.setFontColor(Color.BLUE);
                }
                invalidate();
            }
        }
    

    【讨论】:

      猜你喜欢
      • 2017-11-02
      • 1970-01-01
      • 1970-01-01
      • 2011-06-07
      • 2017-12-23
      • 1970-01-01
      • 2018-08-02
      • 1970-01-01
      • 2020-12-09
      相关资源
      最近更新 更多