Skip to content

Instantly share code, notes, and snippets.

@xxxzhi
Created January 15, 2015 06:48
Show Gist options
  • Save xxxzhi/9872b8d53fa935a64e36 to your computer and use it in GitHub Desktop.
Save xxxzhi/9872b8d53fa935a64e36 to your computer and use it in GitHub Desktop.
From http://stackoverflow.com/questions/7896615/android-how-to-get-value-of-an-attribute-in-code using java to get attribute。 用java 代码去获取属性的值。
TypedValue typedValue = new TypedValue();
// ((Activity)context).getTheme().resolveAttribute(android.R.attr.textAppearanceLarge, typedValue, true);
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();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment