3
如何將圖像設置爲BlackBerry中ButtonField的背景?BlackBerry - 如何將圖像設置爲ButtonField的背景?
如何將圖像設置爲BlackBerry中ButtonField的背景?BlackBerry - 如何將圖像設置爲ButtonField的背景?
我不相信你可以將圖像設置爲ButtonField。相反,您可以擴展BitmapField類,覆蓋trackwheelClick函數並使用onFocus來確定它是否是該字段被單擊。這會產生一個「可點擊」的圖像。
另一種方式是擴展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);
}
}
非常好,謝謝最大! – DecodeGnome 2012-01-18 13:14:36