黑莓自定义ButtonField

时间:2012-06-27 09:23:26

标签: blackberry focus buttonfield

This是我启动活动时的默认外观。

在我使用轮迹垫后,变得像this。按钮图像或整个按钮丢失。

这是我的自定义按钮字段extends ButtonField

public class Custom_ButtonField extends ButtonField {
Bitmap mNormal;
Bitmap mFocused;
Bitmap mActive;

int mWidth;
int mHeight;

public Custom_ButtonField(Bitmap normal, Bitmap focused, 
    Bitmap active) {
    super(CONSUME_CLICK);
    mNormal = normal;
    mFocused = focused;
    mActive = active;
    mWidth = mNormal.getWidth();
    mHeight = mNormal.getHeight();
    setMargin(0, 0, 0, 0);
    setPadding(0, 0, 0, 0);
    setBorder(BorderFactory
                    .createSimpleBorder(new XYEdges(0, 0, 0, 0)));
    setBorder(VISUAL_STATE_ACTIVE, BorderFactory
                    .createSimpleBorder(new XYEdges(0, 0, 0, 0)));
}

protected void paint(Graphics graphics) {
    Bitmap bitmap = null;
    switch (getVisualState()) {
    case VISUAL_STATE_NORMAL:
            bitmap = mNormal;
            break;
    case VISUAL_STATE_FOCUS:
            bitmap = mFocused;
            break;
    case VISUAL_STATE_ACTIVE:
            bitmap = mActive;
            break;
    default:
            bitmap = mNormal;
    }
    graphics.drawBitmap(0, 0, bitmap.getWidth(), bitmap.getHeight(),
                    bitmap, 0, 0);
}

public int getPreferredWidth() {
    return mWidth;
}

public int getPreferredHeight() {
    return mHeight;
}

protected void layout(int width, int height) {
    setExtent(mWidth, mHeight);
}
}

2 个答案:

答案 0 :(得分:1)

看起来您正在尝试使用图片创建一个按钮,这样您最好使用RIM发布的Advanced UI Library。看一下BitmapButtonField课程。

答案 1 :(得分:0)

在构造函数上设置Focusable。

super(Field.FOCUSABLE);