Tuesday, May 4, 2010

More on Android resources ...

Instead of specifying actual values as a resource (e.g. string, colour, etc), it can be referred by an indirection reference string. This is useful, e.g in internationalization, etc.

The format for specifying references resources in the XML file is:
@[package:]type/name
@[package:]+type/name
?[namespace:]type/name

If you are using the Android default package then [package:] can be omitted.

The '@' is for specifying references to the resource, i.e. get the actual value by looking it up as specified by the type and name,e.g.:

android:textColor="@color/opaque_red"

The actual value for opaque_red would have been specified in res/values/colors.xml.

The "+" is for auto-generation of resource value for the resource, generally used for generation the resource identification number, much like SQL auto-increment.

Without the "+" the resource value must have been specified beforehand, i.e in res/values/colors.xml

The "?" allows lookup using the name of the attribute of the resource, e.g.:

android:textColor="?android:textDisabledColor"

No comments:

Post a Comment