1

我有一个按钮字段。它的颜色是红色。当我点击它的颜色时,按钮应该变成黑色怎么办?

4

5 回答 5

1

您可以尝试使用官方 RIM 文档的“教程:创建自定义按钮”

我想这就是你要找的

于 2011-11-24T12:46:37.443 回答
1

try this it is work,

  public int checkBoxFlag1 = 0;
    public int checkBoxFlag2 = 0;
    public int checkBoxFlag3 = 0;

final Bitmap focuscheckButton = Bitmap.getBitmapResource("checkbox_tickmark.png");
        final Bitmap unfocuscheckButton = Bitmap.getBitmapResource("checkbox.png");

        HorizontalFieldManager checkBoxFieldManager = new HorizontalFieldManager(); 

        BitmapField checkBox1 = new BitmapField(unfocuscheckButton,Field.FOCUSABLE)
        {
            protected void paint(Graphics graphics) 
            {
                // TODO Auto-generated method stub
                if(checkBoxFlag1==0)
                {
                    this.setBitmap(unfocuscheckButton);
                }
                else
                {
                    this.setBitmap(focuscheckButton);
                }
                super.paint(graphics);
            }
            protected boolean navigationClick(int status, int time) 
            {
                // TODO Auto-generated method stub
                if(checkBoxFlag1==0)
                {
                    checkBoxFlag1=1;
                }
                else
                {
                    checkBoxFlag1=0;
                }
                return super.navigationClick(status, time);
            }

        };      
        checkBox1.setMargin(0,20,0,20);
        checkBoxFieldManager.add(checkBox1);
于 2012-03-06T10:35:49.513 回答
1

如果你的按钮是一个a class="button"标签,你可以这样做:

a.button {
    color: black;
}
于 2011-11-24T10:13:42.110 回答
1

您是否尝试过本教程“黑莓自定义按钮字段”,或者您也可以制作一个背景设置为一种颜色的位图字段,并为所需的更改实现自定义绘制方法。

于 2011-11-24T09:59:03.523 回答
0

用这个 -

image1 为红色图像按钮,image2 为黑色

reg_can_btn editprofile = new reg_can_btn("", Field.FOCUSABLE |FIELD_HCENTER,  image1, image2, 0x102839);

然后

public class edit_profile_btn extends Field {

private String _label;
private int _labelHeight;
private int _labelWidth;
private Font _font;

private Bitmap _currentPicture;
private Bitmap _onPicture; 
private Bitmap _offPicture; 
int color;

public edit_profile_btn(String text, long style ,String img, String img_hvr, int color){
    super(style);


    _offPicture = Bitmap.getBitmapResource(img);
    _onPicture = Bitmap.getBitmapResource(img_hvr);

    _font = getFont();
    _label = text;
    _labelHeight = _onPicture.getHeight();  
    _labelWidth = _onPicture.getWidth();

    this.color = color;

    _currentPicture = _offPicture;
}

/**
 * @return The text on the button
 */
String getText(){
    return _label;
}

/**
 * Field implementation.
 * @see net.rim.device.api.ui.Field#getPreferredHeight()
 */
public int getPreferredHeight(){
    return _labelHeight;
}

/**
 * Field implementation.
 * @see net.rim.device.api.ui.Field#getPreferredWidth()
 */
public int getPreferredWidth(){
    return _labelWidth;
}

/**
 * Field implementation.  Changes the picture when focus is gained.
 * @see net.rim.device.api.ui.Field#onFocus(int)
 */
protected void onFocus(int direction) {
    _currentPicture = _onPicture;
    invalidate();
}

/**
 * Field implementation.  Changes picture back when focus is lost.
 * @see net.rim.device.api.ui.Field#onUnfocus()
 */
protected void onUnfocus() {
    _currentPicture = _offPicture;
    invalidate();
}

/**
 * Field implementation.  
 * @see net.rim.device.api.ui.Field#drawFocus(Graphics, boolean)
 */
protected void drawFocus(Graphics graphics, boolean on) {
    // Do nothing
}

/**
 * Field implementation.
 * @see net.rim.device.api.ui.Field#layout(int, int)
 */
protected void layout(int width, int height) {
    setExtent(Math.min( width, getPreferredWidth()), 
    Math.min( height, getPreferredHeight()));
}

/**
 * Field implementation.
 * @see net.rim.device.api.ui.Field#paint(Graphics)
 */
protected void paint(Graphics graphics){       
    // First draw the background colour and picture
    //graphics.setColor(this.color);
    graphics.setBackgroundColor(Color.BLACK);
    graphics.fillRect(0, 0, getWidth(), getHeight());
    graphics.drawBitmap(0, 0, getWidth(), getHeight(), _currentPicture, 0, 0);

    // Then draw the text
    graphics.setColor(Color.BLACK);
    graphics.setFont(_font);
    graphics.drawText(_label, 4, 2, 
        (int)( getStyle() & DrawStyle.ELLIPSIS | DrawStyle.HALIGN_MASK ),
        getWidth() - 6 );
}

/**
 * Overridden so that the Event Dispatch thread can catch this event
 * instead of having it be caught here..
 * @see net.rim.device.api.ui.Field#navigationClick(int, int)
 */
protected boolean navigationClick(int status, int time){
    fieldChangeNotify(1);
    return true;
}

}
于 2011-11-28T08:18:15.013 回答