2009-09-02 37 views
5

Tôi có một trường nhãn và ba nút có tên màu đỏ, vàng, xanh lam. Nếu tôi nhấp vào nút màu đỏ thì màu phông chữ của nhãn sẽ thay đổi thành màu đỏ; tương tự như vậy nếu tôi nhấp vào nút màu vàng thì màu phông chữ sẽ thay đổi thành màu vàng; tương tự như vậy, theo màu nút, màu sắc của phông chữ sẽ thay đổi trong trường nhãn.Làm cách nào để thay đổi màu phông chữ của trường nhãn blackberry?

Mọi người có thể cho tôi biết cách thực hiện việc này không?

Trả lời

13

màu Font trong LabelField có thể dễ dàng duy trì bằng cách thiết lập graphics.setColor về sự kiện sơn trước 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(); 
     } 
    } 
+0

nhờ coldice.It của hữu ích – Kumar

+0

Bạn đang chào đón! –

Các vấn đề liên quan