本文主要是介绍Android修改默认字体大小(小、默认、大、最大),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
通常修改屏幕显示大小会通过调整屏幕密度来实现,但这调整的是整体的大小。客户会经常要去调整至合适大小,需要修改字体默认大小可参考本文的内容
需求:字体默认为小
根据packages/apps/Settings/src/com/android/settings/display/FontSizePreferenceController.java
public class FontSizePreferenceController extends BasePreferenceController {public FontSizePreferenceController(Context context, String key) {super(context, key);}@Overridepublic int getAvailabilityStatus() {return AVAILABLE;}@Overridepublic CharSequence getSummary() {final float currentScale = Settings.System.getFloat(mContext.getContentResolver(),Settings.System.FONT_SCALE, 1.0f);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];}
}
可知字体大小是由Settings.System.FONT_SCALE来控制的
根据packages\apps\Settings\src\com\android\settings\display\ToggleFontSizePreferenceFragment.java
@Overridepublic void onCreate(@Nullable Bundle savedInstanceState) {super.onCreate(savedInstanceState);final 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);mInitialIndex = fontSizeValueToIndex(currentScale, strEntryValues);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>
故修改如下:
--- a/alps-mp-t0/vendor/mediatek/proprietary/packages/apps/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java
+++ b/alps-mp-t0/vendor/mediatek/proprietary/packages/apps/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java
@@ -2272,6 +2272,8 @@ class DatabaseHelper extends SQLiteOpenHelper {loadBooleanSetting(stmt, Settings.System.ACCELEROMETER_ROTATION,R.bool.def_accelerometer_rotation);
+
+ loadSetting(stmt, Settings.System.FONT_SCALE, 0.85f);loadIntegerSetting(stmt, Settings.System.USER_ROTATION, R.integer.def_user_rotation);diff --git a/alps-mp-t0/vendor/mediatek/proprietary/packages/apps/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java b/alps-mp-t0/vendor/mediatek/proprietary/packages/apps/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java
old mode 100644
new mode 100755
index 440bb67..6fd6c72
--- a/alps-mp-t0/vendor/mediatek/proprietary/packages/apps/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java
+++ b/alps-mp-t0/vendor/mediatek/proprietary/packages/apps/SettingsProvider/src/com/android/providers/settings/SettingsHelper.java
@@ -360,7 +360,7 @@ public class SettingsHelper {mContext.getContentResolver(), name, defaultScale);return Math.abs(currentScale - defaultScale) >= FLOAT_TOLERANCE;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;default:return false;}
这篇关于Android修改默认字体大小(小、默认、大、最大)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!