Cleaning Up with Styles
Now that you have a working project, take a look at your layout XML. Each button is identical. That is fine for now, but if you want to add an attribute to a button, you will have to repeat your work three times. And what about when you have twelve buttons?
Happily, Android has UI styles, which are meant to eliminate that repetition. Style resources are similar to CSS styles. Each style defines a set of XML attribute-value pairs. Styles can be organized into a hierarchy: a child has the same attributes and values as its parent, but may override them or add additional values.
Like string resources, styles are defined inside of a <resources> tag in an XML file in your res/values folder. Also like strings, the filename ...
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