我的活动中有一个BottomNavigationView,我有五个片段,并且使用了Navigation Jetpack组件。
每次通过单击BottomNavigationView项移至下一个片段时,我都必须询问确认对话框(如果我必须从此屏幕导航,是/否)。如果是,我可以转到下一个屏幕,否则,我必须关闭对话框并继续。
我在Navigation Jetpack组件本身中可以更好地处理这种情况。
我对此没有清晰的图像
[当您选择BottomNavigationView项目时,可以使用此代码;第一步,在onCreate中定义BottomNavigationView。
mBtmView = (BottomNavigationView) findViewById(R.id.bottomView);
mBtmView.setOnNavigationItemSelectedListener(this);
第二步;
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
mMenuId = item.getItemId();
switch (item.getItemId()) {
case R.id.action_food: {
//Show dialog to there. if reject swipe from your dialog, use setCurrentItem.
}
break;
case R.id.action_medical: {
//Show dialog to there. if reject swipe from your dialog, use setCurrentItem.
}
break;
case R.id.action_yoga: {
//Show dialog to there. if reject swipe from your dialog, use setCurrentItem.
}
break;
case R.id.action_postures: {
//Show dialog to there. if reject swipe from your dialog, use setCurrentItem.
}
break;
}
return true;
}