1. Configure the imagebutton defined in the following layout in XML.
<Imagebutton
Android: Id = "@ ID/rte_bold"
Android: layout_width = "40dip"
Android: layout_height = "40dip"
Android: src = "@ drawable/rte_bold_state"
Android: scaletype = "fitxy"
Android: layout_margintop = "5dip"
Android: textsize = "10dip"/>
2. The rte_bold_state layout XML below, in different States ("selected" and "unselected") show different drawbles.
<? XML version = "1.0" encoding = "UTF-8"?>
<Selector xmlns: Android = "http://schemas.android.com/apk/res/android">
<Item Android: state_selected = "true" Android: drawable = "@ drawable/rte_bold_selected"/>
<Item Android: drawable = "@ drawable/rte_bold"/>
</Selector>
3. the following code controls whether the image is selected to change the image:
Boldbutton = (imagebutton) view. findviewbyid (R. Id. rte_bold );
Boldbutton. setonclicklistener (New onclicklistener (){
@ Override
Public void onclick (view v ){
If (boldbutton. isselected ()){
Boldbutton. setselected (false );
}
Else {
Boldbutton. setselected (true );
}
});
If you have any questions, please tell me that I am an android cainiao.