2 回答
TA贡献1821条经验 获得超6个赞
尝试像这样最后返回 true
class ItemSelectedListener implements BottomNavigationView.OnNavigationItemSelectedListener {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
FragmentTransaction transaction = fragmentManager.beginTransaction();
switch (menuItem.getItemId()) {
case R.id.navigation_menu1:
transaction.replace(R.id.frame_home, menu1Fragment).commitAllowingStateLoss();
break;
case R.id.navigation_menu2:
transaction.replace(R.id.frame_home, menu2Fragment).commitAllowingStateLoss();
break;
case R.id.navigation_menu3:
transaction.replace(R.id.frame_home, menu3Fragment).commitAllowingStateLoss();
break;
case R.id.navigation_menu4:
transaction.replace(R.id.frame_home, menu4Fragment).commitAllowingStateLoss();
break;
}
return true;
}
}
TA贡献1780条经验 获得超5个赞
试试这段代码。
return false;
or
return true;
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
// uncheck the other items.
mMenuId = item.getItemId();
for (int i = 0; i < mBtmView.getMenu().size(); i++) {
MenuItem menuItem = mBtmView.getMenu().getItem(i);
boolean isChecked = menuItem.getItemId() == item.getItemId();
menuItem.setChecked(isChecked);
}
switch (item.getItemId()) {
case R.id.action_food: {
}
break;
case R.id.action_medical: {
}
break;
case R.id.action_yoga: {
}
break;
case R.id.action_postures: {
}
break;
}
return true;
}
添加回答
举报