Layer List Drawables

BeatBox is looking good. You now have round buttons, and they visually respond to presses. Time for something a little more advanced.

Layer list drawables allow you to combine two XML drawables into one. Armed with this tool, add a dark ring around your button when it is in the pressed state.

Listing 22.7  Using a layer list drawable (res/drawable/button_beat_box_pressed.xml)

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape xmlns:android="http://schemas.android.com/apk/res/android"
            android:shape="oval">

          <solid android:color="@color/red"/>
        </shape>
    </item>
    <item>
        <shape android:shape="oval">

            <stroke android:width="4dp"
                    android:color="@color/dark_red"/>
        </shape>
    </item> ...

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.