There's precious little documentation about the declare-styleable
tag by which we can declare custom styles for components. I did find this list of valid values for the format
attribute of the attr
tag. While that's nice as far as it goes, it doesn't explain how to use some of those values. Browsing attr.xml (the Android source for the standard attributes), I discovered that you can do things like:
<!-- The most prominent text color. -->
<attr name="textColorPrimary" format="reference|color" />
The format
attribute can evidently be set to a combination of values. Presumably the format
attribute helps the parser interpret an actual style value. Then I discovered this in attr.xml:
<!-- Default text typeface. -->
<attr name="typeface">
<enum name="normal" value="0" />
<enum name="sans" value="1" />
<enum name="serif" value="2" />
<enum name="monospace" value="3" />
</attr>
<!-- Default text typeface style. -->
<attr name="textStyle">
<flag name="normal" value="0" />
<flag name="bold" value="1" />
<flag name="italic" value="2" />
</attr>
Both of these seem to declare a set of allowed values for the indicated style.
So I have two questions:
- What's the difference between a style attribute that can take on one of a set of
enum
values and one that can take on a set offlag
values? - Does anyone know of any better documentation for how
declare-styleable
works (other than reverse engineering the Android source code)?