android 9.0 修改默认字体大小

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;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

码点

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值