Class ImageButton

All Implemented Interfaces:
Drawable.Callback
Direct Known Subclasses:
CheckableImageButton

public class ImageButton extends ImageView

Displays a button with an image (instead of text) that can be pressed or clicked by the user. The image on the surface of the button is defined by the ImageView.setImage(Image) method.

To indicate the different button states (focused, selected, etc.), you can define a different image for each state. E.g., a blue image by default, an orange one for when focused, and a yellow one for when pressed. An easy way to do this is with StateListDrawable and ImageView.setImageDrawable(Drawable). For example:


 StateListDrawable selector = new StateListDrawable();
 selector.addState(new int[]{-R.attr.state_enabled}, disabledIcon);
 selector.addState(new int[]{R.attr.state_checkable, R.attr.state_checked}, checkedIcon);
 selector.addState(new int[]{R.attr.state_checkable}, uncheckedIcon);
 selector.addState(StateSet.WILD_CARD, uncheckableIcon);
 imageButton.setImageDrawable(selector);
 

See CheckableImageButton for checkable image buttons.

See the Buttons guide.