如何更改黑莓标签字段的字体颜色动态? [英] How to change the font color of blackberry label field dynamically?

查看:167
本文介绍了如何更改黑莓标签字段的字体颜色动态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个标签字段并用红,黄,蓝名三个按钮。如果我按一下红色按钮,然后在标签领域的字体颜色应当变红;同样,如果我点击黄色按钮,然后将字体颜色应更改为黄色;同样根据按钮颜色字体的颜色应在标签字段更改。

I have one label field and three buttons with the name of red, yellow, blue. If I click the red button then the label field font color should be change to red; similarly if I click the yellow button then the font color should change to yellow; likewise according to the button color the color of font should change in the label field.

谁能告诉我该怎么做呢?

Can anyone tell me how to do this?

推荐答案

在字体的LabelField通过颜色之前super.paint油漆事件设置graphics.setColor易于维护:

Font color in LabelField is easily maintained by setting graphics.setColor on paint event before super.paint:

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

这篇关于如何更改黑莓标签字段的字体颜色动态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆