Reputation: 73
In my android app I got main_activity.xml:
<android.support.design.widget.NavigationView
android:id="@+id/nav"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:layout_gravity="start"
app:headerLayout="@layout/head"
app:menu="@menu/nav_menu"/>
I would like to change app:menu
value programatically, is there any way to do it?
Upvotes: 1
Views: 63
Reputation: 12382
Crate a NavigationView
object by findViewById
NavigationView mNavigationView = (NavigationView) findViewById(R.id.left_drawer);
You can change it at runtime by using below code...
mNavigationView.getMenu().clear();
mNavigationView.inflateMenu(R.menu.menu);
Upvotes: 1
Reputation:
Use the findViewById() method to get a reference to the NavigationView object.
The NavigationView class provides a method inflateMenu(resourceID).
Upvotes: 2