Chinaunix首页 | 论坛 | 博客
  • 博客访问: 133521
  • 博文数量: 12
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 337
  • 用 户 组: 普通用户
  • 注册时间: 2014-03-12 17:41
个人简介

活到老,学到老

文章分类
我的朋友

分类: Android平台

2014-03-17 11:38:32

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

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

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

点击(此处)折叠或打开

  1. <string-array name="entries_font_size">
  2.         <item msgid="6490061470416867723">Small</item>
  3.         <item msgid="3579015730662088893">Normal</item>
  4.         <item msgid="1678068858001018666">Large</item>
  5.         <item msgid="490158884605093126">Huge</item>
  6.     </string-array>

  7.     <string-array name="entryvalues_font_size" translatable="false">
  8.         <item>0.85</item
  9.         <item>1.0</item>
  10.         <item>1.15</item>
  11.         <item>1.30</item>
  12.     </string-array>
以上配置是通过如下代码加载后供给终端用户选择
packages/app/settings/DisplaySettings.java

点击(此处)折叠或打开

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

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

  10.         // report the current size in the summary text
  11.         final Resources res = getResources();
  12.         String[] fontSizeNames = res.getStringArray(R.array.entries_font_size);
  13.         pref.setSummary(String.format(res.getString(R.string.summary_font_size),
  14.                 fontSizeNames[index]));
  15.     }
在frameworks层会对系统的字体大小设置一个默认值,字体放缩比例为1,也就是对应显示设置中的“普通”字体

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

点击(此处)折叠或打开

  1. /**
  2.      * Set this object to the system defaults.
  3.      */
  4.     public void setToDefaults() {
  5.         fontScale = 1; //此处赋值为默认字体的放缩比例
  6.         mcc = mnc = 0;
  7.         locale = null;
  8.         userSetLocale = false;
  9.         touchscreen = TOUCHSCREEN_UNDEFINED;
  10.         keyboard = KEYBOARD_UNDEFINED;
  11.         keyboardHidden = KEYBOARDHIDDEN_UNDEFINED;
  12.         hardKeyboardHidden = HARDKEYBOARDHIDDEN_UNDEFINED;
  13.         navigation = NAVIGATION_UNDEFINED;
  14.         navigationHidden = NAVIGATIONHIDDEN_UNDEFINED;
  15.         orientation = ORIENTATION_UNDEFINED;
  16.         screenLayout = SCREENLAYOUT_UNDEFINED;
  17.         uiMode = UI_MODE_TYPE_UNDEFINED;
  18.         screenWidthDp = compatScreenWidthDp = SCREEN_WIDTH_DP_UNDEFINED;
  19.         screenHeightDp = compatScreenHeightDp = SCREEN_HEIGHT_DP_UNDEFINED;
  20.         smallestScreenWidthDp = compatSmallestScreenWidthDp = SMALLEST_SCREEN_WIDTH_DP_UNDEFINED;
  21.         densityDpi = DENSITY_DPI_UNDEFINED;
  22.         seq = 0;
  23.     }



阅读(12128) | 评论(0) | 转发(2) |
给主人留下些什么吧!~~