仅更改 Blackberry 中 TextField 标签的颜色

发布于 2024-12-17 03:10:10 字数 149 浏览 5 评论 0原文

我正在尝试添加一个文本字段。我正在使用 EditField _textBox = new EditField("Subject", "Some text"); 用于创建标签为 Subject 的文本框。我只想更改文本框标签(主题)的颜色。

I am trying to a add a TextField. I am using
EditField _textBox = new EditField("Subject", "Some text"); for creating a textbox with label as Subject. I want to change the color of only the label(Subject) of the textbox.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

凉宸 2024-12-24 03:10:10

您将需要一个自定义字段来执行此操作,因为即使您重写 EditField.paint()EditField 标签的颜色>。

我的建议是:

  • 创建一个扩展 Horizo​​ntalFieldManager 的类(例如 CustomEditField),
  • 向其中添加 2 个字段,一个用于标签的 LabelField 和一个 >EditField 用于可编辑文本
  • 重写 LabelField 的 Paint() 方法以设置所需的颜色。

代码如下:

import net.rim.device.api.ui.component.EditField;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.Graphics;

public class CustomEditField extends HorizontalFieldManager{

    private static final int COLOR = 0x00FF0000; //colour for the label 
    private LabelField labelField; //for the label
    private EditField editField; //for the editable text

    public CustomEditField(String label, String initialValue){

        labelField = new LabelField(label){

            public void paint(Graphics g){

            g.setColor(COLOR);
                super.paint(g);
            }

        };

        editField = new EditField("", initialValue); //set the label text to an empty string

        add(labelField);
        add(editField);     
    }   
}

当然,您仍然需要添加方法来设置并从 EditField 获取文本,以及您需要从 EditField 获得的任何其他特定方法,但作为概念证明,这是可行的。

You're going to need a custom field to do this because it is not possible to change the colour of the EditField's label, even if you override EditField.paint().

My suggestion is:

  • Create a class (e.g. CustomEditField) which extends HorizontalFieldManager
  • Add 2 fields to this, a LabelField for the label and an EditField for the editable text
  • Override the paint() method for the LabelField to set the colour which you want.

Here's the code:

import net.rim.device.api.ui.component.EditField;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.Graphics;

public class CustomEditField extends HorizontalFieldManager{

    private static final int COLOR = 0x00FF0000; //colour for the label 
    private LabelField labelField; //for the label
    private EditField editField; //for the editable text

    public CustomEditField(String label, String initialValue){

        labelField = new LabelField(label){

            public void paint(Graphics g){

            g.setColor(COLOR);
                super.paint(g);
            }

        };

        editField = new EditField("", initialValue); //set the label text to an empty string

        add(labelField);
        add(editField);     
    }   
}

Of course, you're still going to need to add in your methods to set and get the text from your EditField, and any other specific methods which you need from EditField, but as a proof of concept this works.

难忘№最初的完美 2024-12-24 03:10:10

您可以重写paint()方法,并可以调用setColor(int RGB)方法来提供您想要的颜色,这可能会有所帮助

You can Override the paint() method and can call the setColor(int RGB) method to give the color you want may be this will help

原来分手还会想你 2024-12-24 03:10:10
EditField _textBox = new EditField("Subject","Some text")
{
public void paint(Graphics g) 
{
        getManager().invalidate();
        g.setColor(_color);
        super.paint(g);
}
}
EditField _textBox = new EditField("Subject","Some text")
{
public void paint(Graphics g) 
{
        getManager().invalidate();
        g.setColor(_color);
        super.paint(g);
}
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文