How can I programmatically open (show in screen) NavigationView

梦想与她 提交于 2021-01-22 00:27:50

问题


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>

回答1:


You need have reference to DrawerLayout

drawerLayout.openDrawer();
drawerLayout.closeDrawer();

use openDrawer and closeDrawer to change menu visibility




回答2:


To improve the code:

drawerLayout.openDrawer(Gravity.LEFT);
drawerLayout.closeDrawer(Gravity.LEFT);


来源:https://stackoverflow.com/questions/32122621/how-can-i-programmatically-open-show-in-screen-navigationview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!