Android 禁用字体随系统大小变化

因为每个人的习惯和视觉不一样,所以会调整系统的字体大小,但是系统字体大小调整后,app的字体也会随着变化,但是变化后布局就会遭到破坏,显示不完整,导致功能被掩盖无法使用,那么如果禁止app的字体随系统的字体调整变化呢?

方法一

把字体的尺寸由sp改为dp,这样字体就不会变化了,但是会对适配造成影响,所以不是最好的方法

方法二

推荐使用createConfigurationContext方法,使用方法在Activity中重写attachBaseContext方法,在此方法下设置字体的显示比例为1

 @Override
 protected void attachBaseContext(Context newBase) {
     Configuration configuration = newBase.getResources().getConfiguration();
     configuration.fontScale=1.0F;
     Context context = newBase.createConfigurationContext(configuration);
     super.attachBaseContext(context);
 }
方法三(

猜你喜欢

转载自blog.csdn.net/xiaopihair123/article/details/135968410
今日推荐