For the More Curious: Accessing Theme Attributes

Once attributes are declared in your theme, you can access them in XML or in code.

To access a theme attribute in XML, you use the notation that you saw on the listSeparatorTextViewStyle attribute in Chapter 8. When referencing a concrete value in XML, such as a color, you use the @ notation. @color/gray points to a specific resource.

When referencing a resource in the theme, you use the ? notation:

    <Button xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/list_item_sound_button"
        android:layout_width="match_parent"
        android:layout_height="120dp"
        android:background="?attr/colorAccent" tools:text="Sound name"/> ...

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

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