Take button as an example:
General Button has 2 states, pressed and normal state
1. Create a new drawable folder under Res to store your own drawable files
2. Create a new pressed and normal shape file under the Drawable folder (which is a picture resource, skip this step)
3. New Button Background Selector file
4. Specify drawable for the backgroud of the button
Code:
Button_noraml.xml
<?xml version= "1.0" encoding= "Utf-8"?>
<shape xmlns:android= "Http://schemas.android.com/apk/res/android" >
<stroke
Android:width= "1DP"
Android:color= "#00FF00"/>
<gradient
Android:angle= "270"
Android:endcolor= "#e5e5e5"
Android:startcolor= "#DCDCDC"/>
</shape>
————————————————————————————————————————————————————
Button_press.xml
<?xml version= "1.0" encoding= "Utf-8"?>
<shape xmlns:android= "Http://schemas.android.com/apk/res/android" >
<!--strokes--
<stroke
Android:width= "1DP"
Android:color= "#00FF00"/>
<!--gradients--
<gradient
Android:angle= "270"
Android:endcolor= "#00FF00"
Android:startcolor= "#90EE90"/>
</shape>
————————————————————————————————————————————————————
Button_selector.xml
<?xml version= "1.0" encoding= "Utf-8"?>
<selector xmlns:android= "Http://schemas.android.com/apk/res/android" >
<!--pressed state drawable--
<item android:drawable= "@drawable/button_press" android:state_pressed= "true" ></item>
<!--normal state of drawable---
<item android:drawable= "@drawable/button_noraml" ></item>
</selector>
————————————————————————————————————————————————————
<?xml version= "1.0" encoding= "Utf-8"?
<linearlayout xmlns:android= "http://schemas.android.com/apk /res/android "
android:layout_width=" match_parent "
android:layout_ height= "Match_parent"
android:orientation= "vertical";
< Button
android:layout_width= "match_parent"
android:layout_height= "Wrap_content"
Android:layout_margin= "30DP"
android:background= "@drawable/button_selector"
android:text= "button"/>
</LINEARLAYOUT>