【发布时间】:2010-06-17 20:14:07
【问题描述】:
我正在使用 Eclipse 开发一个黑莓应用程序,我需要在标签的位置显示图像,例如新按钮在我需要显示一些图像的新按钮的位置。我如何显示图像,你可以举一个例子。
谢谢你
【问题讨论】:
标签: eclipse blackberry
我正在使用 Eclipse 开发一个黑莓应用程序,我需要在标签的位置显示图像,例如新按钮在我需要显示一些图像的新按钮的位置。我如何显示图像,你可以举一个例子。
谢谢你
【问题讨论】:
标签: eclipse blackberry
试试这个
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);
}
};
【讨论】: