开发者

BlackBerry - how to occupy a complete button with image

开发者 https://www.devze.com 2023-01-31 23:59 出处:网络
I have written BlackBerry code to add an image to a ButtonField. I want the whole button to be occupied by the image, but the image is not displayed completely on the ButtonField.

I have written BlackBerry code to add an image to a ButtonField. I want the whole button to be occupied by the image, but the image is not displayed completely on the ButtonField. There is a lot of margin on开发者_开发问答 the top, left and right of the button. I tried to use cellpadding but it didn't work.

How can I reduce the width and height of the ButtonField so it matches the original image size of 41 x 41?


Instead of adding an image to a button extend the image class and turn that into a button by overriding isFocusable(), navigationClick(), trackwheelClick(), and keyChar(). Here's the code:

public class ImageButtonField extends BitmapField
{
    public ImageButtonField(Bitmap image) {
        super(image);
    }

    public boolean isFocusable() {
        return true;
    }

    protected boolean navigationClick(int status, int time) {
        fieldChangeNotify(0);
        return true;
    }

    protected boolean trackwheelClick(int status, int time) {
        fieldChangeNotify(0);
        return true;
    }

    protected boolean keyChar(char character, int status, int time) {
        if(Characters.ENTER == character || Characters.SPACE == character) {
            fieldChangeNotify(0);
            return true;
        }
        return super.keyChar(character, status, time);
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消