I need to know the pixel size of the current Android font by default. I copied the approach indicated 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 is 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()
source share