Android: how to get value of an attribute in code?

Your code only gets the resource ID of the style that the textAppearanceLarge attribute points to, namely TextAppearance.Large as Reno points out.

To get the textSize attribute value from the style, just add this code:

int[] textSizeAttr = new int[] { android.R.attr.textSize };
int indexOfAttrTextSize = 0;
TypedArray a = context.obtainStyledAttributes(typedValue.data, textSizeAttr);
int textSize = a.getDimensionPixelSize(indexOfAttrTextSize, -1);
a.recycle();

Now textSize will be the text size in pixels of the style that textApperanceLarge points to, or -1 if it wasn’t set. This is assuming typedValue.type was of type TYPE_REFERENCE to begin with, so you should check that first.

The number 16973890 comes from the fact that it is the resource ID of TextAppearance.Large

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)