gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 06:41:06 24 4
gpt4 key购买 nike

如何在 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com