[英]How to fix bottom navigation bar not showing correctly
I'm having the problem that when I trying to switch between the menu item.当我尝试在菜单项之间切换时遇到问题。 The menu item will not pointing to the correct icon.菜单项不会指向正确的图标。 here is the flow when i found this problem这是我发现这个问题时的流程
case R.id.nav_home:
//home fragment transaction
actionBar.setTitle("Home");
HomeFragment fragment1 = new HomeFragment();
FragmentTransaction fragmentTransaction1 = getSupportFragmentManager().beginTransaction();
fragmentTransaction1.replace(R.id.content, fragment1, "");
fragmentTransaction1.commit();
break;
case R.id.nav_features:
//features fragment transaction
startActivity(new Intent(DashboardActivity.this, FeaturesActivity.class));
break;
onBackPressed();
how can I make the system point to the correct menu item?如何使系统指向正确的菜单项?
You should return a boolean
for this method:您应该为此方法返回boolean
:
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
//...
}
do this:做这个:
case R.id.nav_home:
//home fragment transaction
actionBar.setTitle("Home");
HomeFragment fragment1 = new HomeFragment();
FragmentTransaction fragmentTransaction1 =
getSupportFragmentManager().beginTransaction();
fragmentTransaction1.replace(R.id.content, fragment1, "");
fragmentTransaction1.commit();
return true; // add this line and remove break;
if you don't want to select icon after click, you can return false
.如果您不想点击 select 图标后,可以返回false
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.