State List Drawables

To fix this, define a new shape drawable that will be used for the pressed state of the button.

Create button_beat_box_pressed.xml in res/drawable. Make this pressed drawable the same as the normal version but with a red background color.

Listing 22.4  Defining a pressed shape drawable (res/drawable/button_beat_box_pressed.xml)

<shape xmlns:android=""

    <solid android:color="@color/red"/>


Next, you are going to use this pressed version when the user presses the button. To do this, you will use a state list drawable.

A state list drawable is a drawable that points to other drawables based on the state of something. A button has ...

Get Android Programming: The Big Nerd Ranch Guide, 4th Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.