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 ...

Get Android Programming: The Big Nerd Ranch Guide now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.