简体   繁体   中英

BlackBerry - how to occupy a complete button with image

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM