質問

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.

役に立ちましたか?

解決

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.

他のヒント

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

EditField _textBox = new EditField("Subject","Some text")
{
public void paint(Graphics g) 
{
        getManager().invalidate();
        g.setColor(_color);
        super.paint(g);
}
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top