原文:http://blog.chinaunix.net/uid-29535415-id-4150770.html
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;
}