Hide a Navigation Drawer Menu Item - Android

后端 未结 8 652
春和景丽
春和景丽 2021-01-30 06:31

I have a navigation drawer. When an event is called, I want to hide one of my navigation menu item for user. How can I do that?

protected void onCreate(Bundle sa         


        
8条回答
  •  有刺的猬
    2021-01-30 06:46

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);
    
    Menu menu =navigationView.getMenu();
    
    MenuItem target = menu.findItem(R.id.nav_target);
    
    target.setVisible(false);
    

提交回复
热议问题