android系统字体大小在“设置” 中“显示”中“字体大小”设置,一共提四种等级设置:小 、普通 、 大、 超大
四种等级选择相应配置代码位置
packages/apps/setttings/res/values/arrays.xml
-
<string-array name="entries_font_size">
-
<item msgid="6490061470416867723">Small</item>
-
<item msgid="3579015730662088893">Normal</item>
-
<item msgid="1678068858001018666">Large</item>
-
<item msgid="490158884605093126">Huge</item>
-
</string-array>
-
-
<string-array name="entryvalues_font_size" translatable="false">
-
<item>0.85</item>
-
<item>1.0</item>
-
<item>1.15</item>
-
<item>1.30</item>
-
</string-array>
以上配置是通过如下代码加载后供给终端用户选择
packages/app/settings/DisplaySettings.java
-
public void readFontSizePreference(ListPreference pref) {
-
try {
-
mCurConfig.updateFrom(ActivityManagerNative.getDefault().getConfiguration());
-
} catch (RemoteException e) {
-
Log.w(TAG, "Unable to retrieve font size");
-
}
-
-
// mark the appropriate item in the preferences list
-
int index = floatToIndex(mCurConfig.fontScale);
-
pref.setValueIndex(index);
-
-
// report the current size in the summary text
-
final Resources res = getResources();
-
String[] fontSizeNames = res.getStringArray(R.array.entries_font_size);
-
pref.setSummary(String.format(res.getString(R.string.summary_font_size),
-
fontSizeNames[index]));
-
}
在frameworks层会对系统的字体大小设置一个默认值,字体放缩比例为1,也就是对应显示设置中的“普通”字体
frameworks/base/core/java/android/content/res/Configuration.java
-
/**
-
* Set this object to the system defaults.
-
*/
-
public void setToDefaults() {
-
fontScale = 1; //此处赋值为默认字体的放缩比例
-
mcc = mnc = 0;
-
locale = null;
-
userSetLocale = false;
-
touchscreen = TOUCHSCREEN_UNDEFINED;
-
keyboard = KEYBOARD_UNDEFINED;
-
keyboardHidden = KEYBOARDHIDDEN_UNDEFINED;
-
hardKeyboardHidden = HARDKEYBOARDHIDDEN_UNDEFINED;
-
navigation = NAVIGATION_UNDEFINED;
-
navigationHidden = NAVIGATIONHIDDEN_UNDEFINED;
-
orientation = ORIENTATION_UNDEFINED;
-
screenLayout = SCREENLAYOUT_UNDEFINED;
-
uiMode = UI_MODE_TYPE_UNDEFINED;
-
screenWidthDp = compatScreenWidthDp = SCREEN_WIDTH_DP_UNDEFINED;
-
screenHeightDp = compatScreenHeightDp = SCREEN_HEIGHT_DP_UNDEFINED;
-
smallestScreenWidthDp = compatSmallestScreenWidthDp = SMALLEST_SCREEN_WIDTH_DP_UNDEFINED;
-
densityDpi = DENSITY_DPI_UNDEFINED;
-
seq = 0;
-
}
阅读(1776) | 评论(0) | 转发(0) |