Android Change Navigation Drawer Menu Items Text programmatically

前端 未结 5 1387
暗喜
暗喜 2021-01-30 20:33

I have the new Navigation Drawer in my app and I want to change the navigation view menu items title text dynamically from code. I have watched many posts but I can\'t figure ou

5条回答
  •  遥遥无期
    2021-01-30 21:33

    Change the code like below in case you rename or remove item from navigation menu drawer list

      NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
        if (navigationView != null) {
            Menu menu = navigationView.getMenu();
            menu.findItem(R.id.nav_profile).setTitle("My Account");
            menu.findItem(R.id.nav_mng_task).setTitle("Control Task");
            //menu.findItem(R.id.nav_pkg_manage).setVisible(false);//In case you want to remove menu item
            navigationView.setNavigationItemSelectedListener(this);
        }
    

提交回复
热议问题