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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access