BlackBerry应用程序可以有图像按钮吗?

时间:2011-05-17 18:07:19

标签: blackberry button

  

可能重复:
  Image Button in BlackBerry

有没有办法让照片成为黑莓手机中的按钮?试着写一个匹配的游戏。

泰德

1 个答案:

答案 0 :(得分:0)

下面的代码可以帮助您:

public class ImageButtonFieldTest extends Field {

private Bitmap image;
private Bitmap selectedImage;
private int height;
private int width;

public ImageButtonField(Bitmap image, Bitmap selectedImage) {
    this.image = image;
    this.selectedImage = selectedImage;
    this.height = image.getHeight();
    this.width = image.getWidth();
}

protected void layout(int maxWidth, int maxHeight) {  
    setExtent(image.getWidth(), image.getHeight());
}

protected void paint(Graphics graphics) {

    // Draw img             
    if (isFocus()) {
        graphics.drawBitmap(0, 0, width, height, selectedImage, 0, 0);
    } else {
        graphics.drawBitmap(0, 0, width, height, image, 0, 0);
    }
}

public boolean isFocusable() {
    return true;
}

protected void drawFocus(Graphics graphics, boolean on) {        // Don't draw the default focus  
}

protected void onFocus(int direction) {
    super.onFocus(direction);
    invalidate();
}

protected void onUnfocus() {
    super.onUnfocus();
    invalidate();
}

}