Crete resources aliases
you can even use resources in XML to create aliases. For example, you can create adrawable resource that is an alias for another drawable resource:
<?xml version="1.0" encoding="utf-8"?> <bitmap xmlns:android="http://schemas.android.com/apk/res/android" android:src="@drawable/other_drawable" />
This sounds redundant, but can be very useful when using alternative resource. Read more aboutCreating alias resources.
Referencing style attributes
A style attribute resource allows you to reference the valueof an attribute in the currently-applied theme. Referencing a style attribute allows you tocustomize the look of UI elements by styling them to match standard variations supplied by thecurrent theme, instead of supplying a hard-coded value. Referencing a style attributeessentially says, "use the style that is defined by this attribute, in the current theme."
To reference a style attribute, the name syntax is almost identical to the normal resourceformat, but instead of the at-symbol (@
), use a question-mark (?
), and theresource type portion is optional. For instance:
?[<package_name>:][<resource_type>/]<resource_name>
For example, here's how you can reference an attribute to set the text color to match the"primary" text color of the system theme:
<EditText id="text" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textColor="?android:textColorSecondary" android:text="@string/hello_world" />
Here, the android:textColor
attribute specifies the name of a style attributein the current theme. Android now uses the value applied to theandroid:textColorSecondary
style attribute as the value for android:textColor
in this widget. Because the systemresource tool knows that an attribute resource is expected in this context,you do not need to explicitly state the type (which would be?android:attr/textColorSecondary
)—you can exclude theattr
type.