美文网首页
Android中设置字体不随系统字体大小而变化

Android中设置字体不随系统字体大小而变化

作者: toExploreFuture | 来源:发表于2021-10-20 09:14 被阅读0次

如果自己的app 没有适配 大号字体


//设置字体为默认大小,不随系统字体大小改而改变
    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        if (newConfig.fontScale != 1)//非默认值
            getResources();
        super.onConfigurationChanged(newConfig);
    }
 
 
    @Override
    public Resources getResources() {
        Resources res = super.getResources();
        if (res.getConfiguration().fontScale != 1) {//非默认值
            Configuration newConfig = new Configuration();
            newConfig.setToDefaults();//设置默认
            res.updateConfiguration(newConfig, res.getDisplayMetrics());
        }
        return res;
}



相关文章

网友评论

      本文标题:Android中设置字体不随系统字体大小而变化

      本文链接:https://www.haomeiwen.com/subject/okxtaltx.html