使用setSwipeBackEnabled(false)关闭滑动返回时崩溃
ListZimo opened this issue · comments
ListZimo commented
在BaseActivity的onCreate中初始化后,在继承BaseActivity中启用
**if (mSwipeBackHelper != null){
mSwipeBackHelper.setSwipeBackEnabled(false);
}**关闭侧滑返回时崩溃
报错信息:### java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.ViewGroup.setTranslationX(float)' on a null object reference
ListZimo commented
问题已经解决
在子Activity下重写dispatchTouchEvent,
@OverRide
public boolean dispatchTouchEvent(MotionEvent ev) {
if (mSwipeBackHelper != null) {
mSwipeBackHelper.dispatchTouchEvent(ev);
mSwipeBackHelper.setSwipeBackEnabled(false);
}
return super.dispatchTouchEvent(ev);
}
可以在子Activity中关闭滑动返回;
Simon_Lee commented
感谢反馈,setSwipeBackEnabled中没有做非空判断,下一个版本会进行改进。