Reference: http://www.mkyong.com/android/android-imagebutton-selector-example/
Http://developer.android.com/guide/topics/ui/controls.html
1. Create a new Filename.xml file under the Res/drawable folder:
<?XML version= "1.0" encoding= "Utf-8"?><selectorxmlns:android= "Http://schemas.android.com/apk/res/android"> <Itemandroid:drawable= "@drawable/button_pressed_yellow"android:state_pressed= "true"/> <Itemandroid:drawable= "@drawable/button_focused_orange"android:state_focused= "true"/> <Itemandroid:drawable= "@drawable/button_normal_green"/></selector>
Normal state: Button_normal_green.png
When clicked: Button_pressed_yellow.png
2.Button configuration:
<ButtonAndroid:id= "@+id/button1"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:layout_alignparenttop= "true"Android:layout_centerhorizontal= "true"Android:layout_margintop= "86DP"Android:text= "button"Android:background= "@drawable/drawable" />
3.Activity Code:
@Override protected void OnCreate (Bundle savedinstancestate) { super .oncreate (Savedinstancestate); Setcontentview (R.layout.activity_main); Button button = new Onclicklistener () {@Override public void OnClick (View v) {toast.maketext (mainactivity. this , "CC"
Change button icon when clicked