Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
User interface 如何动态更改blackberry标签字段的字体颜色?_User Interface_Blackberry - Fatal编程技术网

User interface 如何动态更改blackberry标签字段的字体颜色?

User interface 如何动态更改blackberry标签字段的字体颜色?,user-interface,blackberry,User Interface,Blackberry,我有一个标签字段和三个按钮,分别是红色、黄色和蓝色。如果单击红色按钮,则标签字段字体颜色应更改为红色;类似地,如果我单击黄色按钮,则字体颜色应更改为黄色;同样,根据按钮颜色,标签字段中的字体颜色也应改变 有人能告诉我怎么做吗?通过在super.paint之前设置graphics.setColor on paint事件,可以轻松维护LabelField中的字体颜色: class FCLabelField extends LabelField { public FCLabel

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


有人能告诉我怎么做吗?

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

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