比如第三方库的Activity是:PictureSelectorSupporterActivity、PictureSelectorTransparentActivity、CropImageActivity
1.在自定义Application 的 onCreate 方法设置:
@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()方法:
/**
* 取消第三方库适配
* @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();
}
3.Activity监听
@Override
public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle savedInstanceState) {
}
@Override
public void onActivityStarted(@NonNull Activity activity) {
}
@Override
public void onActivityResumed(@NonNull Activity activity) {
this.curentActivity = activity;
}
@Override
public void onActivityPaused(@NonNull Activity activity) {
}
@Override
public void onActivityStopped(@NonNull Activity activity) {
}
@Override
public void onActivitySaveInstanceState(@NonNull Activity activity, @NonNull Bundle outState) {
}
@Override
public void onActivityDestroyed(@NonNull Activity activity) {
}
AndroidAutoSize地址:https://github.com/JessYanCoding/AndroidAutoSize