BlackBerry - how to occupy a complete button with image

前提是你 提交于 2019-12-19 10:44:12

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/4509519/blackberry-how-to-occupy-a-complete-button-with-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!