版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
自定义控件在系统修改字体大小后,适配的难度会增加不少。
因为sp是谷歌推荐,所以用dp这种不是最好的选择。
可以在Activity的中去屏蔽系统设置的字号:
@Override
public Resources getResources() {
Resources res = super.getResources();
Configuration config = new Configuration();
config.setToDefaults();
res.updateConfiguration(config, res.getDisplayMetrics());
return res;
}
这样,就不会因为老年人字体而变成各种各样的奇怪大小了