O'Reilly logo

Android Programming: The Big Nerd Ranch Guide by Brian Hardy, Bill Phillips

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

State List Drawables

As good as they look, these buttons are still static. Under the covers, the old Button background was using a state list drawable. State list drawables allow you to display a different drawable for each state its associated View is in. (You previously used a state list drawable to change the background of list items in Chapter 18.) There are a lot of different states, but here you are only interested in whether the button is being pressed or not.

Start off by creating the look for your pressed button. This look will be same as the normal button look except for the color.

In the package explorer, make a copy of button_shape_normal.xml and name it button_shape_pressed.xml. Open button_shape_pressed.xml and add 180 degrees ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required