安卓字型不隨系統字型變化
阿新 • • 發佈:2018-11-05
app字型不隨著系統設定變大變小
在基類BaseActivity 裡面設定即可,重寫getResources()方法
具體程式碼如下
原文地址:https://www.jianshu.com/p/059f3bad61b2
@Override
public Resources getResources() {
Resources resources = super.getResources();
Configuration newConfig = resources.getConfiguration();
DisplayMetrics displayMetrics = resources.getDisplayMetrics();if (resources != null && newConfig.fontScale != 1) {
newConfig.fontScale = 1;
if (Build.VERSION.SDK_INT >= 17) {
Context configurationContext = createConfigurationContext(newConfig);
resources = configurationContext.getResources();
displayMetrics.scaledDensity = displayMetrics.density * newConfig.fontScale;
} else {
resources.updateConfiguration(newConfig, displayMetrics);
}
}
return resources;
}