黑莓自定义按钮字段



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

在我玩轮式触控板之后,然后变成这样。按钮图像或整个按钮丢失。

这是我的自定义按钮字段,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);
}
}

看起来您正在尝试创建一个带有图像的按钮,因此最好使用 RIM 发布的高级 UI 库。看看BitmapButtonField类。

Set Focusable on constructor。

super(Field.FOCUSABLE);

相关内容

  • 没有找到相关文章

最新更新