Android4.4默认字体大小

修改Android4.4默认字体大小

    全志A33项目中,有些客户使用高清屏,字体有点小,要求把默认字体改成“Large”或“Huge”;  此时我们会想到一个关键词“fontScale”跟踪到 frameworks/base/core/java/android/content/res/Configuration.java 文件中的 setToDefaults()函数,如下:

  public void setToDefaults() {
        fontScale = 1;//此处设置的是“normal”,此处可以修改为1.15、1.3 ,是一种方法
        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;
    }

   我们如果想在build.prop中添加一个属性去控制它,每次修改起来就不用那么麻烦,可以如下:

  ......
 import android.os.SystemProperties; //添加系统属性的重要类
   ......
 public void setToDefaults() {
        /* add property to control the default value of font scale,Await */
        fontScale = Float.parseFloat(SystemProperties.get("ro.font.scale", "1.0"));//add Await
        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;
    }

而后,我们只需在build.prop中加入ro.font.scale=1.0 / 1.15 /1.3 去控制系统字体大小就可以了

你可能感兴趣的:(ro.font.scale,fontScale)