如何以编程方式更改 NavigationView 的菜单?

Ang*_*l R 5 android attributes kotlin

您好,我想知道如何从 NavigationView 更改菜单 ID,在这种情况下,它是在用户单击 RadioButton 时触发的。我已经有了那部分,但我只需要知道如何更改菜单,因此在菜单中,单击 RadioButton 时它将显示不同的选项。

private var radioAdm:RadioButton? = null
private var radioAtle:RadioButton? = null
private var atletanav:BottomNavigationView? = null
private var menuopt = "@menu/admin_menu"

override fun onCheckedChanged(buttonView: CompoundButton?, isChecked: Boolean) {
     // Here is where I need to put that code
    }
Run Code Online (Sandbox Code Playgroud)

我已经试过了,但没有成功:

atleta_navbar.set(menu){menu=menuopt}
atleta_navbar.setTag(menuopt)
Run Code Online (Sandbox Code Playgroud)

所以在 NavigationView 它将从这个开始:

在此处输入图片说明

对此:

在此处输入图片说明

nav*_*ver 5

在java中,你可以尝试在运行时重新膨胀NavigationView。

navigationView.getMenu().clear(); //clear old inflated items.
navigationView.inflateMenu(R.menu.new_navigation_drawer_items);
Run Code Online (Sandbox Code Playgroud)

我不懂kotlin,但想法是一样的。