http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList
"You can describe the state list in an XML file. Each graphic is represented by an <item> element inside a single <selector>
element. Each <item> uses various attributes to describe the state in which it should be used as the graphic for the drawable."
Here is an example:
1) Save this file in res/drawable as button_selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/rounded_rect_no_gradient" android:state_pressed="true"/>
<item android:drawable="@drawable/rounded_rect_w_gradient"/>
</selector>
2) Save this file in res/drawable as rounded_rect_no_gradient.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="#BD33ff00" />
<corners android:radius="3dp" />
<stroke android:width="5px" />
</shape>
3) Save this file in res/drawable as rounded_rect_w_gradient.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<gradient
android:angle="270"
android:endColor="#BD33ff00"
android:startColor="#BDffffff" />
<corners android:radius="3dp" />
</shape>
4) In your layout.xml add a reference to the button_selector.xml file.
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="@drawable/button_selector" />
This is the official Android example:
http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList
XML file saved at res/drawable/button.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="@drawable/button_pressed" /> <!-- pressed -->
<item android:state_focused="true"
android:drawable="@drawable/button_focused" /> <!-- focused -->
<item android:state_hovered="true"
android:drawable="@drawable/button_focused" /> <!-- hovered -->
<item android:drawable="@drawable/button_normal" /> <!-- default -->
</selector>
This layout XML applies the state list drawable to a Button:
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="@drawable/button" />