Reading Android style information at runtime
<p>I'm trying to retrieve Android style values at runtime, so I can apply them within a custom component. <a href="http://stackoverflow.com/questions/3237752/android-set-textview-style-at-runtime">(Passing a style ID as the 3rd parameter to an embedded View's constructor doesn't seem to work.)</a> I've found <code>Context. obtainStyledAttributes(int, int[])</code>, but this seems to mysteriously fail to retrieve specific attributes that I know are set in the style. (That is, when the <code>int[]</code> of <code>android.R.attr.*</code> values contains a mix of attributes that are specified in the style and attributes that are <strong>not</strong> specified in the style, the <code>TypedArray</code> will have a value (<em>i.e.</em> <code>TypedArray. hasValue(int)</code>) for some, but not all, of the attributes that are specified in the style.)</p>

<p>I've also found <code>Resources. obtainTypedArray(int)</code>, and it seems to always have all the values in the style - but it seems very hard to use. The issue is that the values don't seem to specify which attribute they are for - they simply appear in the order that the attributes appear in the <code>&lt;style&gt;</code> resource. </p>

<ul>
<li><p>Even in the special case where I know which style I'm examining, I
can't make assumptions about the order of the attributes: someone may
come along and sort them alphabetically, or functionally, or
randomly. </p></li>
<li><p>In the more general case where I need to handle whichever
style resource the user may have specified, I need to probe by
<code>android.R.attr.*</code> value.</p></li>
</ul>

<p>So, my question: <strong>Is there any way to find which attributes, in which order, a style contains?</strong></p>

<p>I can call <code>Resources. getIntArray( styleId )</code>, but this does <em>not</em> give me an <code>int[]</code> of <code>android.R.attr.*</code> values!</p>
