Note that there are some explanatory texts on larger screens.

plurals
  1. PODeclaring styleable attributes in Android
    primarykey
    data
    text
    <p>There's precious little documentation about the <code>declare-styleable</code> tag by which we can declare custom styles for components. I did find <a href="http://chaosinmotion.com/blog/?p=179" rel="noreferrer">this list</a> of valid values for the <code>format</code> attribute of the <code>attr</code> tag. While that's nice as far as it goes, it doesn't explain how to use some of those values. Browsing <a href="https://android.googlesource.com/platform/frameworks/base/+/master/core/res/res/values/attrs.xml" rel="noreferrer">attr.xml</a> (the Android source for the standard attributes), I discovered that you can do things like:</p> <pre><code>&lt;!-- The most prominent text color. --&gt; &lt;attr name="textColorPrimary" format="reference|color" /&gt; </code></pre> <p>The <code>format</code> attribute can evidently be set to a combination of values. Presumably the <code>format</code> attribute helps the parser interpret an actual style value. Then I discovered this in attr.xml:</p> <pre><code>&lt;!-- Default text typeface. --&gt; &lt;attr name="typeface"&gt; &lt;enum name="normal" value="0" /&gt; &lt;enum name="sans" value="1" /&gt; &lt;enum name="serif" value="2" /&gt; &lt;enum name="monospace" value="3" /&gt; &lt;/attr&gt; &lt;!-- Default text typeface style. --&gt; &lt;attr name="textStyle"&gt; &lt;flag name="normal" value="0" /&gt; &lt;flag name="bold" value="1" /&gt; &lt;flag name="italic" value="2" /&gt; &lt;/attr&gt; </code></pre> <p>Both of these seem to declare a set of allowed values for the indicated style.</p> <p>So I have two questions:</p> <ol> <li>What's the difference between a style attribute that can take on one of a set of <code>enum</code> values and one that can take on a set of <code>flag</code> values?</li> <li>Does anyone know of any better documentation for how <code>declare-styleable</code> works (other than reverse engineering the Android source code)?</li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload