I need to know the size in pixels of the current default Android font. I copied the approach listed in a very similar question here. However, instead of getting the size in pixels, I always get -1. Any ideas what I'm doing wrong?
Here's the code:
Context context = getActivity();
TypedValue typedValue = new TypedValue();
context.getTheme().resolveAttribute(android.R.attr.textAppearance, typedValue, true);
int[] textSizeAttr = new int[] { android.R.attr.textSize };
TypedArray a = context.obtainStyledAttributes((AttributeSet) typedValue.string, textSizeAttr);
textSize = a.getDimensionPixelSize(0, -1);
Log.e("Metrics", "text size in dp = " + String.valueOf(textSize));
a.recycle()