In my app I want to pass certain menu depending of some condition.
This is the layout:
<android.support.design.widget.NavigationView
android:id="@+id/nav_view_free"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
android:background="@color/Color_White"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer_1"
/>
All I want to do is to change dynamically the @menu/activity_main_drawer_1 depending of some condition.
How can I do this programmatically?
To use a DrawerLayout, position your primary content view as the first child with width and height of match_parent and no layout_gravity> . Add drawers as child views after the main content view and set the layout_gravity appropriately. Drawers commonly use match_parent for height with a fixed width.
Use inflateMenu
on your NavigationView
.
For example:
navigationView.getMenu().clear();
navigationView.inflateMenu(R.menu.menu_view);
See here for more information.
navigationView.getMenu().clear();
navigationView.inflateMenu(R.menu.your_menu);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With