Blackberry Clickable BitmapField

强颜欢笑 提交于 2019-11-28 11:38:28

问题


I want to create a Custom BitmapField for putting Icons on my Menu Screen. I want them to be Clicked. I also want to give the X and Y coordinates of the icon as parameter to the Custom BitmapField. How can I do that?


回答1:


public class CustomMenuButtonField extends Field{
Bitmap normal,focused;
public CustomMenuButtonField(String bitmap1, String bitmap2) {

    normal = Bitmap.getBitmapResource(bitmap1);
    focused = Bitmap.getBitmapResource(bitmap2);

}

protected void layout(int width, int height) {
    setExtent(width, height); // Set them according to your design  
}

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

public boolean isFocusable() {
    return true;
}

protected void paint(Graphics graphics) {

    if(isFocus())
    {
        graphics.drawBitmap(0, 0, width, height, focused, 0, 0);
    }
    else
    {
        graphics.drawBitmap(0, 0, width, height, normal, 0, 0);
    }

}

}

If you want to give coordinates as parameters , add them. Height and width is up to you..



来源:https://stackoverflow.com/questions/5722875/blackberry-clickable-bitmapfield

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