1. Prepare 3 images for button states, and put it into resource/drawable
folder.
2. create a new XML file in res/drawable/
folder, in whatever name you want, in this case, we just give a name as my_button.xml
. This file defined which button state is belong to which image.
Now, you can refer to this button via this Id : @drawable/my_button.
File : res/drawable/my_button.xml
create xml file using the button image like this with my_button.xml
in drawable
folder
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/button_pressed_yellow"
android:state_pressed="true" />
<item android:drawable="@drawable/button_focused_orange"
android:state_focused="true" />
<item android:drawable="@drawable/button_normal_green" />
</selector>
add a normal button, and attach the background image to above “my_button” via
android:background:@drawable/my_button
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…