How do I get the value of a Theme attribute programmatically?
For example:
Theme:
<style name="Theme">
... truncated ....
<item name="textAppearanceLarge">@android:style/TextAppearance.Large</item>
</style>
Code:
int textSize = ???? // how do I get Theme.textAppearanceLarge?
EDIT: too many answers that don't address the question.
use this function :
myView.setTextAppearance(Context context, int resid)
//Sets the text color, size, style, hint color, and highlight color from the specified TextAppearance resource.
see : http://developer.android.com/reference/android/widget/TextView.html#setTextAppearance%28android.content.Context,%20int%29
From TextView.java this is what the above function does:
public void setTextAppearance(Context context, int resid) {
TypedArray appearance =
context.obtainStyledAttributes(resid,
com.android.internal.R.styleable.TextAppearance);
int color;
ColorStateList colors;
int ts;
.
.
.
ts = appearance.getDimensionPixelSize(com.android.internal.R.styleable.
TextAppearance_textSize, 0);
if (ts != 0) {
setRawTextSize(ts);
}
int typefaceIndex, styleIndex;
typefaceIndex = appearance.getInt(com.android.internal.R.styleable.
TextAppearance_typeface, -1);
styleIndex = appearance.getInt(com.android.internal.R.styleable.
TextAppearance_textStyle, -1);
setTypefaceByIndex(typefaceIndex, styleIndex);
appearance.recycle();
}
This is another way of doing this. Do make sure you recycle the appearance (TypedArray obect). Hope this helps!
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