修改android系统默认字体大小

原文:http://blog.chinaunix.net/uid-29535415-id-4150770.html

android系统字体大小在“设置” 中“显示”中“字体大小”设置,一共提四种等级设置:小 、普通 、 大、 超大

四种等级选择相应配置代码位置

packages/apps/setttings/res/values/arrays.xml


    <string-array name="entries_font_size">
            <item msgid="6490061470416867723">Small</item>
            <item msgid="3579015730662088893">Normal</item>
            <item msgid="1678068858001018666">Large</item>
            <item msgid="490158884605093126">Huge</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>

以上配置是通过如下代码加载后供给终端用户选择
packages/app/settings/DisplaySettings.java

    public void readFontSizePreference(ListPreference pref) {
            try {
                mCurConfig.updateFrom(ActivityManagerNative.getDefault().getConfiguration()); 
            } catch (RemoteException e) {
                Log.w(TAG, "Unable to retrieve font size");
            }

            // mark the appropriate item in the preferences list
            int index = floatToIndex(mCurConfig.fontScale);
            pref.setValueIndex(index);

            // report the current size in the summary text
            final Resources res = getResources();
            String[] fontSizeNames = res.getStringArray(R.array.entries_font_size);
            pref.setSummary(String.format(res.getString(R.string.summary_font_size),
                    fontSizeNames[index]));
        }



在frameworks层会对系统的字体大小设置一个默认值,字体放缩比例为1,也就是对应显示设置中的“普通”字体

frameworks/base/core/java/android/content/res/Configuration.java


    /**
         * Set this object to the system defaults.
         */
        public void setToDefaults() {
            fontScale = 1; //此处赋值为默认字体的放缩比例
            mcc = mnc = 0;
            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;
            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;
            seq = 0;
        }



  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值