How can I programmatically open (show in screen) NavigationView? I can't find any function what can be helpfull.
I have this xml file:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
//...
<android.support.design.widget.NavigationView
android:id="@+id/navigation"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="@layout/nav_header"
app:itemTextColor="#333"
app:itemIconTint="#333"
app:menu="@menu/navigation_drawer_items" />
</android.support.v4.widget.DrawerLayout>
You need have reference to DrawerLayout
drawerLayout.openDrawer();
drawerLayout.closeDrawer();
use openDrawer and closeDrawer to change menu visibility
To improve the code:
drawerLayout.openDrawer(Gravity.LEFT);
drawerLayout.closeDrawer(Gravity.LEFT);
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