【发布时间】:2013-02-27 04:46:26
【问题描述】:
我需要知道当前默认 Android 字体的像素大小。我复制了一个非常相似的问题here 中列出的方法。但是,我总是得到-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()
【问题讨论】: