Java code will not be pasted, only the xml file will be mounted,
Method:
1. Put three images in drawable, which are the images that obtain the focus, press the focus, lose the focus, and press the focus, and the natural state (that is, the focus is lost, and the focus is not pressed ). Here you prepare three photos.
2. Create an imagebutton. xml file in the drawable folder. The content in the file is:
<Selector xmlns: android = "http://schemas.android.com/apk/res/android">
<Item
Android: state_focused = "true"
Android: state_pressed = "false"
Android: drawable = "@ drawable/snake"/>
<Item
Android: state_focused = "true"
Android: state_pressed = "true"
Android: drawable = "@ drawable/solitaire"/>
<Item www.2cto.com
Android: state_focused = "false"
Android: state_pressed = "true"
Android: drawable = "@ drawable/solitaire"/>
<Item
Android: drawable = "@ drawable/tunes"> </item>
</Selector>
3. reference the xml file in the layout file:
<ImageButton
Android: id = "@ + id/imgButton"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: background = "@ drawable/image_button"
Author: yanzi1225627