通常修改屏幕表现巨细会通过调整屏幕密度来实现,但这调整的是整体的巨细。客户会经常要去调整至符合巨细,必要修改字体默认巨细可参考本文的内容
需求:字体默以为小
根据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);
- 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
- @Override
- public 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;
- }
复制代码
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |