在修改rom中,有时会遇到需要修改系统默认字体的尺寸大小的,我的方法是修改framework里的Configuration.class类,它的位置是在platform/framework/base/core/java/android/content/res/Configuration.java,
public final class Configuration implements Parcelable, Comparable<Configuration> {
/** @hide */
public static final Configuration EMPTY = new Configuration();
/**
* Current user preference for the scaling factor for fonts, relative
* to the base density scaling.
*/
public float fontScale;//定义了系统的字体尺寸
这个类还实现了Parcelable,支持intent或者IPC的传递,可以看到下面定义了public的浮点型变量fontScale,官方英文说明是可按照用户喜好来定义字体的基本尺寸,这就是我们要找的东西了。
/**
* Construct an invalid Configuration. You must call {@link #setToDefaults}
* for this object to be valid. {@more}
*/
public Configuration() {
setToDefaults();
}
这个类的空参数构造函数里调用了这个setToDefaults(),看方法名字就是设置默认的意思,看看里面有什么,
/**
* Set this object to the system defaults.
*/
public void setToDefaults() {
-- //fontScale = 1;//系统原本的默认值
++ fontScale = 1.3f;//自己定义的值
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;
simSetLocale = false; /// M: sim locale feature
}
这个方法的第一句就是改了上述的字体尺寸的浮点值fontScale,系统默认是1,可以按照不同的需求改成自己想要的值,我的是改成了1.3f,当然这个类里面还可以改很多的默认的值,有空再慢慢琢磨了。