代码路径: frameworks/base/core/java/android/content/res/Configuration.java frameworks/base/ packages/SettingsProvider/res/values/defaults.xml frameworks/base/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java 方法一:在Configuration.java文件中修改字体大小 在Configuration.java文件中setToDefaults() 这个方法中将fontScale修改为1.5
/**
* Set this object to the system defaults.
*/
public void setToDefaults() {
fontScale = 1;
mcc = mnc = 0;
mLocaleList = LocaleList.getEmptyLocaleList();
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;
colorMode = COLOR_MODE_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;
assetsSeq = ASSETS_SEQ_UNDEFINED;
seq = 0;
windowConfiguration.setToDefaults();
}
Settings中系统的字体大小,在/packages/apps/Settings/res/values/arrays.xml文件中的,”entryvalues_font_size”这个tag中分别有定义对应的数值
<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>
方法二:在SettingsProvider应用中修改字体大小 1、在defaults.xml文件中定义一个字体大小
<fraction name="def_font_scale">120%</fraction>
2、在DatabaseHelper.java文件中loadSystemSettings()方法中设置默认字体大小
private void loadSystemSettings(SQLiteDatabase db) {
SQLiteStatement stmt = null;
try {
stmt = db.compileStatement("INSERT OR IGNORE INTO system(name,value)"
+ " VALUES(?,?);");
loadBooleanSetting(stmt, Settings.System.DIM_SCREEN,
R.bool.def_dim_screen);
loadIntegerSetting(stmt, Settings.System.SCREEN_OFF_TIMEOUT,
R.integer.def_screen_off_timeout);
// Set default cdma DTMF type
loadSetting(stmt, Settings.System.DTMF_TONE_TYPE_WHEN_DIALING, 0);
// Set default hearing aid
loadSetting(stmt, Settings.System.HEARING_AID, 0);
// Set default tty mode
loadSetting(stmt, Settings.System.TTY_MODE, 0);
loadIntegerSetting(stmt, Settings.System.SCREEN_BRIGHTNESS,
R.integer.def_screen_brightness);
loadIntegerSetting(stmt, Settings.System.SCREEN_BRIGHTNESS_FOR_VR,
com.android.internal.R.integer.config_screenBrightnessForVrSettingDefault);
loadBooleanSetting(stmt, Settings.System.SCREEN_BRIGHTNESS_MODE,
R.bool.def_screen_brightness_automatic_mode);
loadBooleanSetting(stmt, Settings.System.ACCELEROMETER_ROTATION,
R.bool.def_accelerometer_rotation);
loadDefaultHapticSettings(stmt);
loadBooleanSetting(stmt, Settings.System.NOTIFICATION_LIGHT_PULSE,
R.bool.def_notification_pulse);
loadUISoundEffectsSettings(stmt);
loadIntegerSetting(stmt, Settings.System.POINTER_SPEED,
R.integer.def_pointer_speed);
// UNISOC:Bug 1001981 add navigation bar feature support for multil users @{
// set default navigation bar values.
loadIntegerSetting(stmt, Settings.System.NAVIGATION_BAR_CONFIG,
R.integer.def_navigation_bar_config);
loadIntegerSetting(stmt, Settings.System.NAVIGATION_BAR_SHOW,
R.integer.def_navigation_bar_show);
loadFractionSetting(stmt, Settings.System.FONT_SCALE, R.fraction.def_font_scale, 1);
/*@}*/
/*
* IMPORTANT: Do not add any more upgrade steps here as the global,
* secure, and system settings are no longer stored in a database
* but are kept in memory and persisted to XML.
*
* See: SettingsProvider.UpgradeController#onUpgradeLocked
*/
} finally {
if (stmt != null) stmt.close();
}
}
用命令控制字体大小
Settings.System.FONT_SCALE
adb shell settings put system font_scale 1.2
|