Imagebutton can be used flexibly in Android, either in. Java or in. XML, but it is more advantageous in. xml. Code The above two methods are described:
1. One is in the code
Software Development
Your own images
M_imagebutton.setimagedrawable (getresources (). getdrawable (R. drawable. my_button ));
Images provided by the system
M_imagebutton.setimagedrawable (getresources (). getdrawable (Android. R. drawable. sym_call_incoming ));
2. One is in an XML file.
Your own images
Android: src = "http://www.cnblogs.com/@drawable/ic_media_play"
Images provided by the system
Android: src = "@ Android: drawable/sym_call_incoming"
3. The background image of the specified button, including state_pressed and state_focused, represents the status when you press down and focus stays (controlled by direction keys, etc.).
The default value is false. The following figure shows the background image when the image is pressed.
Arrears
Add in Main. XML,
Android: Background = "@ drawable/button_add_x.
Add a button_add_x under Res/drawable. XML file
<? XML version = "1.0" encoding = "UTF-8"?>
<Selector xmlns: Android = "http://schemas.android.com/apk/res/android">
<Item Android: state_pressed = "true"
Android: drawable = "@ drawable/ic_media_select"/>
</Selector>