How To Get Theme Attributes Values
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(..))
Solution 1:
For example, to get editTextColor attribute's value of a theme called MyTheme:
TypedArray a = getTheme().obtainStyledAttributes(
R.style.MyTheme,
newint[] { 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();
Solution 2:
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.
Solution 3:
if you need it in the xml file, you can use something like this:
style="?android:attr/panelTextAppearance"
for example:
<TextViewstyle="?android:attr/panelTextAppearance"android:paddingTop="?android:attr/paddingTop"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="@string/your_text"
/>
if you're using eclipse, control+click on the item, to see other possible values (a file attrs.xml will open).
Post a Comment for "How To Get Theme Attributes Values"