0

これは、アクティビティを起動したときのデフォルトの外観です。

ホイールトラックパッドで遊んだら、このようになります。ボタンの画像またはボタン全体が失われました。

これが私のカスタムボタンフィールドです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);
}
}
4

2 に答える 2

1

画像付きのボタンを作成しようとしているようですので、RIMが公開している高度なUIライブラリを使用したほうがよい場合があります。BitmapButtonFieldクラスを見てください。

于 2012-06-27T10:51:54.417 に答える
0

コンストラクターに Focusable を設定します。

super(Field.FOCUSABLE);
于 2012-06-27T11:51:10.393 に答える