user-interface - BlackBerry - 如何将图像设置为 ButtonField 的背景?

标签 user-interface image blackberry button

如何在 BlackBerry 中将图像设置为 ButtonField 的背景?

最佳答案

其他方式是扩展ButtonField并在油漆上绘制图像:

class BitmapButtonField extends ButtonField {
    Bitmap mNormal;
    Bitmap mFocused;
    Bitmap mActive;

    int mWidth;
    int mHeight;

    public BitmapButtonField(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);
    }
}

sample of use

关于user-interface - BlackBerry - 如何将图像设置为 ButtonField 的背景?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2643083/

相关文章:

java - 线程在中断或停止后不会停止

java - 如何在 JavaFX 中锁定按钮的位置?

python - Python 中的评级控制

css - 在响应式设计中更改 img src?

java - 请告诉我何时在 java 中使用 getInstance() 方法。

java - 从字符串数组到 block 图

html - 尝试并排获取 3 张图像,并在 HTML/CSS 中使用下面的链接

php - 地理定位和 GeoIP 替代方案

blackberry - 在 BlackBerry 上开发多种屏幕尺寸

html - 背景图像上的图像