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="http://schemas.android.com/apk/res/android"
       android:shape="oval">

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

</shape>

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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.