User interface BlackBerry-如何将图像设置为ButtonField的背景?
如何将图像设置为BlackBerry中ButtonField的背景?我不相信您可以将图像设置为。相反,您可以扩展该类、重写该函数并使用来确定是否单击了该字段。这将产生一个“可点击”的图像。另一种方法是在油漆上延伸和绘制图像:User interface BlackBerry-如何将图像设置为ButtonField的背景?,user-interface,image,blackberry,button,User Interface,Image,Blackberry,Button,如何将图像设置为BlackBerry中ButtonField的背景?我不相信您可以将图像设置为。相反,您可以扩展该类、重写该函数并使用来确定是否单击了该字段。这将产生一个“可点击”的图像。另一种方法是在油漆上延伸和绘制图像: class BitmapButtonField extends ButtonField { Bitmap mNormal; Bitmap mFocused; Bitmap mActive; int mWidth; int mHeig
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);
}
}