In my application, I am programmatically populating my NavigationView
menu with something like
val menu = navigation.menu
menu.setGroupCheckable(MENU_GROUP, true, true)
val subMenu = menu.addSubMenu(MENU_GROUP, 0, 0, "New group")
subMenu.add(0, 0, 0, "item 1").apply { isCheckable = true }
subMenu.add(0, 1, 1, "item 2").apply { isCheckable = true }
subMenu.add(0, 2, 2, "item 3").apply { isCheckable = true }
subMenu.add(0, 3, 3, "item 4").apply { isCheckable = true }
val subMenu1 = menu.addSubMenu(MENU_GROUP, 1, 1, "New group 2")
subMenu1.add(1, 0, 0, "item 1").apply { isCheckable = true }
subMenu1.add(1, 1, 1, "item 2").apply { isCheckable = true }
subMenu1.add(1, 2, 2, "item 3").apply { isCheckable = true }
subMenu1.add(1, 3, 3, "item 4").apply { isCheckable = true }
This allows me to get any of those "item *" MenuItem
s to be selectable but I am not able to select any of the SubMenu
headers.
Checkable items appear only in submenus or context menus.
This is my understanding of it, however I am having a hard time finding a way around it. The Material Components NavigationView
specifically does different cases for these two types of menu's
My current solution essentially re-implements a menu with normal views to achieve this. Is there any way to avoid this and just get the SubMenu
to be selectable / checkable directly?