android 9.0 修改默认字体大小
先修改设置的显示
默认是1.0,小是0.85
packages/apps/Settings/src/com/android/settings/display/FontSizePreferenceController.java
public class FontSizePreferenceController extends BasePreferenceController {
public FontSizePreferenceController(Context context, String key) {
super(context, key);
}
@Override
public int getAvailabilityStatus() {
return AVAILABLE;
}
@Override
public CharSequence getSummary() {
final float currentScale = Settings.System.getFloat(mContext.getContentResolver(),
// Settings.System.FONT_SCALE, 1.0f);
Settings.System.FONT_SCALE, 0.85f);
final Resources res = mContext.getResources();
final String[] entries = res.getStringArray(R.array.entries_font_size);
final String[] strEntryValues = res.getStringArray(R.array.entryvalues_font_size);
final int index = ToggleFontSizePreferenceFragment.fontSizeValueToIndex(currentScale,
strEntryValues);
return entries[index];
}
}
packages/apps/Settings/src/com/android/settings/accessibility/ToggleFontSizePreferenceFragment.java
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mActivityLayoutResId = R.layout.font_size_activity;
mPreviewSampleResIds = new int[]{R.layout.font_size_preview};
Resources res = getContext().getResources();
final ContentResolver resolver = getContext().getContentResolver();
// Mark the appropriate item in the preferences list.
mEntries = res.getStringArray(R.array.entries_font_size);
final String[] strEntryValues = res.getStringArray(R.array.entryvalues_font_size);
final float currentScale =
// Settings.System.getFloat(resolver, Settings.System.FONT_SCALE, 1.0f);
Settings.System.getFloat(resolver, Settings.System.FONT_SCALE, 0.85f);
android.util.Log.e(TAG, "onCreate: currentScale:"+currentScale );
android.util.Log.e(TAG, "onCreate: strEntryValues:"+strEntryValues );
mInitialIndex = fontSizeValueToIndex(currentScale, strEntryValues);
android.util.Log.e(TAG, "onCreate: mInitialIndex:"+mInitialIndex );
mValues = new float[strEntryValues.length];
for (int i = 0; i < strEntryValues.length; ++i) {
mValues[i] = Float.parseFloat(strEntryValues[i]);
}
getActivity().setTitle(R.string.title_font_size);
}
这里要注意
packages/apps/Settings/res/values/arrays.xml
<string-array name="entries_font_size">
<item msgid="6490061470416867723">Small</item>
<item msgid="3579015730662088893">Default</item>
<item msgid="1678068858001018666">Large</item>
<item msgid="490158884605093126">Largest</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>
设置里面就是这些显示需要修改的,接下是是系统相关的
frameworks/base/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java
主要是这个
在loadSecureSettings方法中添加:
loadSetting(stmt, Settings.System.FONT_SCALE, 0.85f);
private void loadSecureSettings(SQLiteDatabase db) {
SQLiteStatement stmt = null;
try {
stmt = db.compileStatement("INSERT OR IGNORE INTO secure(name,value)"
+ " VALUES(?,?);");
loadSetting(stmt, Settings.System.FONT_SCALE, 0.85f);
loadStringSetting(stmt, Settings.Secure.LOCATION_PROVIDERS_ALLOWED,
R.string.def_location_providers_allowed);
在loadSecureSettings方法中添加:
loadStringSetting(stmt, Settings.Secure.DISPLAY_DENSITY_FORCED, R.string.display_density_forced);
loadIntegerSetting(stmt, Settings.Secure.SLEEP_TIMEOUT,
R.integer.def_sleep_timeout);
loadStringSetting(stmt, Settings.Secure.DISPLAY_DENSITY_FORCED, R.string.display_density_forced);
frameworks/base/packages/SettingsProvider/res/values/defaults.xml
<string name="display_density_forced">408</string>
408这个值看具体的机器
frameworks/base/packages/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java
在isAlreadyConfiguredCriticalAccessibilitySetting方法中修改
case Settings.System.FONT_SCALE:
// return Settings.System.getFloat(mContext.getContentResolver(), name, 1.0f) != 1.0f;
return Settings.System.getFloat(mContext.getContentResolver(), name, 0.85f) != 0.85f;
最后一处是比较容易忽略的:
\frameworks\base\core\java\android\provider
Settings.java
// private static final float DEFAULT_FONT_SCALE = 1.0f;
private static final float DEFAULT_FONT_SCALE = 0.85f;