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 in the pressed state.

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

<​l​a​y​e​r​-​l​i​s​t​ ​x​m​l​n​s​:​a​n​d​r​o​i​d​=​"​h​t​t​p​:​/​/​s​c​h​e​m​a​s​.​a​n​d​r​o​i​d​.​c​o​m​/​a​p​k​/​r​e​s​/​a​n​d​r​o​i​d​"​>​
 ​ ​<​i​t​e​m​>​ ​ ​ ​ ​<​s​h​a​p​e​ ​ ​ ​ ​ ​ ​ ​ ​a​n​d​r​o​i​d​:​s​h​a​p​e​=​"​o​v​a​l​"​>​ ​ ​ ​ ​ ​ ​ ​ ​<​s​o​l​i​d​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​a​n​d​r​o​i​d​:​c​o​l​o​r​=​"​@​c​o​l​o​r​/​r​e​d​"​/​>​ ...

Get Android Programming: The Big Nerd Ranch Guide, 2nd 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.