关闭

修改android系统默认字体大小

443人阅读 评论(1) 收藏 举报
分类:

原文: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
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:6666次
    • 积分:115
    • 等级:
    • 排名:千里之外
    • 原创:2篇
    • 转载:19篇
    • 译文:0篇
    • 评论:2条
    文章分类
    最新评论