I want to create a Custom BitmapFiel开发者_JAVA技巧d 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?
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..
精彩评论