Step 1 Create three different layer_list xml in a drawable folder for three different button states. For example, the name of these xml is layer1.xml, layer2.xml, layer3.xml
<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <gradient android:angle="270" android:startColor="#0000ff" android:endColor="#0000dd" android:type="linear" /> </shape> </item> </layer-list>
Step 2 create an xml selector named btn_background.xml and pass the layer_list xml attribute in the drawable attribute
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:drawable="@drawable/layer1"> </item> <item android:state_focused="true" android:drawable="@drawable/layer2"> </item> <item android:drawable="@drawable/layer3"> </item> </selector>
step 3 Set the xml selector as the background of the android:background="@drawable/btn_background" button android:background="@drawable/btn_background"
Sunil Kumar Sahoo Dec 01 '11 at 10:30 2011-12-01 10:30
source share