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="">
        <shape xmlns:android=""

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

            <stroke android:width="4dp"
    </item> ...

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.