【问题标题】:Can a BlackBerry application have an image button? [duplicate]黑莓应用程序可以有图像按钮吗? [复制]
【发布时间】:2011-05-18 19:51:54
【问题描述】:

可能重复:
Image Button in BlackBerry

有没有办法让图片成为黑莓中的按钮?正在尝试编写匹配游戏。

泰德

【问题讨论】:

标签: blackberry button


【解决方案1】:

以下代码可能对您有所帮助:

公共类 ImageButtonFieldTest 扩展字段 {

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();
}

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多