- You can use the Android: src attribute or setimageresource (INT) method to set imagebutton images.
- If the image displayed by imagebutton cannot completely overwrite the background color, use imagebutton to set the background color to another image or directly set it to transparent.
<? XML version = "1.0" encoding = "UTF-8"?>
<Tablelayout xmlns: Android = "http://schemas.android.com/apk/res/android"
Android: Orientation = "vertical" Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent">
<Tablerow Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content">
< Textview Android: Id = "@ + ID/tvemail" Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content" Android: ellipsize = "end"
Android: autolink = "email" Android: text = "email \ n (such as sunnychuh@163.com)"/>
< Edittext Android: Id = "@ + ID/etemail" Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content" Android: hint = "Enter your email address"
Android: selectallonfocus = "true"/>
</Tablerow>
<Tablerow Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content">
<Textview Android: Id = "@ + ID/tvphone" Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content" Android: ellipsize = "Middle"
Android: autolink = "email" Android: text = "phone \ n (e.g., 1234567890):"/>
<Edittext Android: Id = "@ + ID/etphone" Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content" Android: maxwidth = "160px"
Android: phonenumber = "true" Android: singleline = "true"
Android: selectallonfocus = "true"/>
</Tablerow>
<Tablerow Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content">
<Button Android: Id = "@ + ID/button01" Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content" Android: gravity = "right"
Android: text = "display"/>
< Imagebutton Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content" Android: src = "@ drawable/myselector"
Android: Background = "@ color/ABC"/>
</Tablerow>
</Tablelayout>
Here, Android: SRC of imagebutton creates myselector. XML in drawable-mdpi:
<? XML version = "1.0" encoding = "UTF-8"?>
<Selector xmlns: Android = "http://schemas.android.com/apk/res/android">
<Item Android: state_pressed = "false" Android: drawable = "@ drawable/img01"/>
<Item Android: state_pressed = "true" Android: drawable = "@ drawable/img02"/>
</Selector>
After you press imagebutton, the following information is displayed: