Android Navigation View set menu programmatically

Use inflateMenu on your NavigationView.

For example:

navigationView.getMenu().clear();
navigationView.inflateMenu(R.menu.menu_view);

See here for more information.


This should work:

val menu = navigationView.menu
val submenu = menu.addSubMenu("New set")

submenu.add("Item1")
submenu.getItem(0).setIcon(R.drawable.item1)
submenu.add("Item2")
submenu.getItem(1).setIcon(R.drawable.item2)
submenu.add("Item3")
submenu.getItem(2).setIcon(R.drawable.item3)
navigationView.invalidate()

Hope it helps.


navigationView.getMenu().clear(); navigationView.inflateMenu(R.menu.your_menu);