I'm trying to retrieve Android style values at runtime, so I can apply them within a custom component. (Passing a style ID as the 3rd parameter to an embedded View's constructor doesn't seem to work.) I've found Context. obtainStyledAttributes(int, int[])
, but this seems to mysteriously fail to retrieve specific attributes that I know are set in the style. (That is, when the int[]
of android.R.attr.*
values contains a mix of attributes that are specified in the style and attributes that are not specified in the style, the TypedArray
will have a value (i.e. TypedArray. hasValue(int)
) for some, but not all, of the attributes that are specified in the style.)
I've also found Resources. obtainTypedArray(int)
, 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 <style>
resource.
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.
In the more general case where I need to handle whichever style resource the user may have specified, I need to probe by
android.R.attr.*
value.
So, my question: Is there any way to find which attributes, in which order, a style contains?
I can call Resources. getIntArray( styleId )
, but this does not give me an int[]
of android.R.attr.*
values!