Android 屏蔽系统设置字号

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/rikkatheworld/article/details/100008665

自定义控件在系统修改字体大小后,适配的难度会增加不少。
因为sp是谷歌推荐,所以用dp这种不是最好的选择。

可以在Activity的中去屏蔽系统设置的字号:

  @Override
    public Resources getResources() {
        Resources res = super.getResources();
        Configuration config = new Configuration();
        config.setToDefaults();
        res.updateConfiguration(config, res.getDisplayMetrics());
        return res;
    }

这样,就不会因为老年人字体而变成各种各样的奇怪大小了

猜你喜欢

转载自blog.csdn.net/rikkatheworld/article/details/100008665