Android强制字体不随系统改变而改变
程序员文章站
2022-07-13 15:52:40
...
@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());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
createConfigurationContext(newConfig);
} else {
res.updateConfiguration(newConfig, res.getDisplayMetrics());
}
}
return res;
}