References to Theme Attributes

Another kind of resource value allows you to reference the value of an attribute in the current theme. This attribute reference can only be used in style resources and XML attributes; it allows you to customize the look of UI elements by changing them to standard variations supplied by the current theme, instead of supplying more concrete values.

As an example, we can use this in our layout to set the text color to one of the standard colors defined in the base system theme:

<?xml version="1.0" encoding="utf-8"?> <EditText id="text"

xmlns:android="" android:layout_width="fill_parent" android:layout_height="fill_parent" android:textColor="?android:textDisabledColor" android:text="@string/hello_world" />

Note that this is very similar to a resource reference, except we are using an '?' prefix instead of '@'. When you use this markup, you are supplying the name of an attribute resource that will be looked up in the theme -- because the resource tool knows that an attribute resource is expected, you do not need to explicitly state the type (which would be


Other than using this resource identifier to find the value in the theme instead of raw resources, the name syntax is identical to the '@' format: ?[namespace:]type/name with the type here being optional.

0 0

Post a comment