Is it possible to obtain styled attributes values from particular Theme without setting the theme up to application/activity? (I mean before invoking context.setTheme(..)
)
The Attr interface represents an attribute in an Element object. Typically the allowable values for the attribute are defined in a schema associated with the document.
attr/colorSurface A color for surfaces of components, such as cards, sheets, and menus.
For example, to get editTextColor attribute's value of a theme called MyTheme:
TypedArray a = getTheme().obtainStyledAttributes( R.style.MyTheme, new int[] { R.attr.editTextColor }); // Get color hex code (eg, #fff) int intColor = a.getColor(0 /* index */, 0 /* defaultVal */); String hexColor = Integer.toHexString(intColor); // Don't forget to recycle a.recycle();
JavaDoc:
method
TypedArray
android.content.res.Resources.Theme.obtainStyledAttributes(int[]
attrs)Return a
TypedArray
holding the values defined by Theme which are listed in attrs.Be sure to call
TypedArray.recycle()
when you are done with the array.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With