设置Android apk字体大小不跟随系统字体变化

两种实现方式:

1、字体大小(textSize)设置dp 为单位。

android:textSize="12dp"

2、在Application 或者BaseActivity 重写一下方法。

@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;
}

猜你喜欢

转载自www.cnblogs.com/scoftlin/p/9023673.html