废话不多说,直接贴代码
禁止系统字体缩放
在BaseActivity中或具体Activity中 添加如下代码
@Override
public Resources getResources() {
Resources res = super.getResources();
Configuration config = new Configuration();
config.setToDefaults();
res.updateConfiguration(config, res.getDisplayMetrics());
return res;
}
禁止系统显示缩放
在BaseActivity中或具体Activity中 添加如下代码
@Override
public Resources getResources() {
Resources res = super.getResources();
Configuration config = new Configuration();
config.densityDpi = getDefaultDisplayDensity();
res.updateConfiguration(config, res.getDisplayMetrics());
return res;
}
public static int getDefaultDisplayDensity() {
try {
Class aClass = Class.forName("android.view.WindowManagerGlobal");
Method method = aClass.getMethod("getWindowManagerService");
method.setAccessible(true);
Object iwm = method.invoke(aClass);
Method getInitialDisplayDensity = iwm.getClass().getMethod("getInitialDisplayDensity", int.class);
getInitialDisplayDensity.setAccessible(true);
Object densityDpi = getInitialDisplayDensity.invoke(iwm, Display.DEFAULT_DISPLAY);
return (int) densityDpi;
} catch (Exception e) {
e.printStackTrace();
return -1;
}
}
大功告成
|