禁止系统放大字体
2022-06-01 本文已影响0人
苏坡坡要吃婆婆酥
@Override
public Resources getResources() {
try {
Resources res = super.getResources();
Configuration current = res.getConfiguration();
if (current != null) {
Log.d(Constant.TAG, "Application getResources config: " + current.fontScale + "-" + current.densityDpi
+ "-" + current.screenWidthDp + "-" + current.screenHeightDp);
if (current.fontScale != 1) {//非默认值
// 禁用字体大小调整
current.fontScale = 1;
res.updateConfiguration(current, res.getDisplayMetrics());
}
try {
// 禁用显示大小调整
DisplayMetrics displayMetrics = res.getDisplayMetrics();
float density = displayMetrics.density;
float scaleDensity = displayMetrics.scaledDensity;
float densityDpi = displayMetrics.densityDpi;
if (scaleDensity != density) {
displayMetrics.scaledDensity = density; // 禁用显示大小调整
}
Log.d(Constant.TAG, "Application getResources density: " + "-" + densityDpi + " - " + density + " scaleDensity: " + scaleDensity);
} catch (Exception e) {
e.printStackTrace();
}
}
return res;
} catch (Exception e) {
e.printStackTrace();
}
return super.getResources();
}
`
放到Application就行。