比如第三方库的Activity是:PictureSelectorSupporterActivity、PictureSelectorTransparentActivity、CropImageActivity
1.在自定义Application 的 onCreate 方法设置:
java
@Override
public void onCreate() {
super.onCreate();
this.mApp=this;
registerActivityLifecycleCallbacks(this);
//取消第三方Activity适配
AutoSizeConfig.getInstance().getExternalAdaptManager().addCancelAdaptOfActivity(PictureSelectorSupporterActivity.class);
AutoSizeConfig.getInstance().getExternalAdaptManager().addCancelAdaptOfActivity(PictureSelectorTransparentActivity.class);
AutoSizeConfig.getInstance().getExternalAdaptManager().addCancelAdaptOfActivity(CropImageActivity.class);
}
2.重写Activity的getResourse()方法:
java
/**
* 取消第三方库适配
* @return
*/
@Override
public Resources getResources() {
Log.i(TAG, "getResources");
Activity curentActivity = null;
if (getApplication()!=null) {
curentActivity = ((MyApp) getApplication()).curentActivity;
}
//第三方库的Activity
if (curentActivity instanceof PictureSelectorSupporterActivity
|| curentActivity instanceof PictureSelectorTransparentActivity
|| curentActivity instanceof CropImageActivity) {
AutoSizeCompat.cancelAdapt(super.getResources());//取消适配
} else {
//适配自己项目的Activity
AutoSizeCompat.autoConvertDensityOfGlobal(super.getResources());//如果没有自定义需求用这个方法
AutoSizeConfig.getInstance().setDesignWidthInDp(1920);//已1920宽度比例 适配屏幕
}
return super.getResources();
}
AndroidAutoSize地址:https://github.com/JessYanCoding/AndroidAutoSize