我需要知道当前默认的Android字体大小(以像素为单位)。我复制了一个非常类似的问题这里列出的方法。但是,我得到的总是-1而不是以像素为单位的大小。有任何想法我做错了什么吗?
这是代码:
这是代码:
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()