我正在使用Eclipse开发一个Blackberry应用程序,我需要在标签位置显示图像,例如新按钮就在新按钮的位置我需要显示一些图像。如何展示图片,请举一个例子。
感谢你
答案 0 :(得分:1)
试试这个
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Graphics;
public class CustomButton extends Field {
final Bitmap bitmap1;
final Bitmap bitmap2;
Bitmap bitmap;
CustomButton() {
bitmap1 = Bitmap.getBitmapResource("button_01.jpg");
bitmap2 = Bitmap.getBitmapResource("button_02.jpg");
bitmap = bitmap1;
}
public int getPreferredHeight() {
return bitmap1.getHeight();
}
public int getPreferredWidth() {
return bitmap1.getWidth();
}
protected void paint(Graphics g) {
g.drawBitmap(0, 0, getWidth(), getHeight(), bitmap, 0, 0);
}
protected void fieldChangeNotify(int context) {
try {
getChangeListener().fieldChanged(this, context);
} catch (Exception exception) {
}
}
public boolean isFocusable() {
return true;
}
protected void layout(int width, int height) {
setExtent(Math.min(width, getPreferredWidth()), Math.min(height,
getPreferredHeight()));
}
protected void onFocus(int direction) {
bitmap = bitmap2;
invalidate();
}
protected boolean navigationClick(int status, int time) {
fieldChangeNotify(1);
return true;
}
protected void onUnfocus() {
bitmap = bitmap1;
invalidate();
}
}
并像这样打电话
CustomButton button = new CustomButton(){
protected void fieldChangeNotify(int context) {
//button click
super.fieldChangeNotify(context);
}
};