The Blackberry SDK provided ButtonField class doesn’t allow much customization. It is Grey when not selected, and when selected it is highlighted. The highlight color depends on the current theme. Because the ButtonField doesn’t allow you to customize its appearance you must create your own custom field if you wish to do so. CustomImageButtonField
class below is almost identical to the standard ButtonField, it allows you to specify the the highlight color and background image. And also it is capable of event handling.
import net.rim.device.api.system.Bitmap; import net.rim.device.api.ui.DrawStyle; import net.rim.device.api.ui.Field; import net.rim.device.api.ui.Graphics; import net.rim.device.api.ui.XYEdges; public class CustomImageButtonField extends Field implements DrawStyle { private Bitmap _currentPicture; private Bitmap _onPicture; private Bitmap _offPicture; private int backgroundColor; private int height, width; public CustomImageButtonField(String onImage, String offImage, int backgroundColor) { super(); this.backgroundColor=backgroundColor; _offPicture = Bitmap.getBitmapResource(offImage); _onPicture = Bitmap.getBitmapResource(onImage); _currentPicture = _offPicture; height = _offPicture.getHeight(); width = _offPicture.getWidth(); } public CustomImageButtonField(String onImage, String offImage, int backgroundColor, XYEdges padding) { this(onImage, offImage, backgroundColor ); setPadding(padding); } public int getPreferredHeight() { return height; } public int getPreferredWidth() { return width; } public boolean isFocusable() { return true; } protected void onFocus(int direction) { _currentPicture = _onPicture; invalidate(); } protected void onUnfocus() { _currentPicture = _offPicture; invalidate(); } protected void layout(int width, int height) { setExtent(Math.min(width, getPreferredWidth()), Math.min(height,getPreferredHeight())); } protected void fieldChangeNotify(int context) { try { this.getChangeListener().fieldChanged(this, context); } catch (Exception exception) { } } protected boolean navigationClick(int status, int time) { fieldChangeNotify(1); return true; } protected void paint(Graphics graphics) { graphics.setColor(backgroundColor); graphics.fillRect(0, 0, getWidth(), getHeight()); graphics.drawBitmap(0, 0, getWidth(), getHeight(), _currentPicture, 0, 0); } }