比如第三方库的Activity是:PictureSelectorSupporterActivity、PictureSelectorTransparentActivity、CropImageActivity
1.在自定义Application 的 onCreate 方法设置:
@Overridepublic 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()方法:
/*** 取消第三方库适配* @return*/@Overridepublic 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 {//适配自己项目的ActivityAutoSizeCompat.autoConvertDensityOfGlobal(super.getResources());//强制用这个方法效果好点,要不然有出现忽大忽小AutoSizeConfig.getInstance().setDesignWidthInDp(1920);//已1920宽度比例 适配屏幕}return super.getResources();}
3.Activity监听
@Overridepublic void onActivityCreated(@NonNull Activity activity, @Nullable Bundle savedInstanceState) {}@Overridepublic void onActivityStarted(@NonNull Activity activity) {}@Overridepublic void onActivityResumed(@NonNull Activity activity) {this.curentActivity = activity;}@Overridepublic void onActivityPaused(@NonNull Activity activity) {}@Overridepublic void onActivityStopped(@NonNull Activity activity) {}@Overridepublic void onActivitySaveInstanceState(@NonNull Activity activity, @NonNull Bundle outState) {}@Overridepublic void onActivityDestroyed(@NonNull Activity activity) {}
AndroidAutoSize地址:https://github.com/JessYanCoding/AndroidAutoSize