Navigation drawer is not closing while navigation item is selected

廉价感情. 提交于 2020-01-04 05:46:08

问题


I am creating a navigation drawer. the drawer is not closing while i select the list item in the navigation drawer. Here is my code

<LinearLayout
    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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <include
        layout="@layout/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>


    <!-- This DrawerLayout has two children at the root  -->


    <android.support.v4.widget.DrawerLayout
        android:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <!-- This LinearLayout represents the contents of the screen  -->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">
            <!-- The main content view where fragments are loaded -->
            <FrameLayout
                android:id="@+id/flContent"
                android:layout_width="match_parent"
                android:layout_height="match_parent"/>

        </LinearLayout>

        <ListView
            android:id="@+id/listViewNavDrawer"
            android:layout_width="match_parent"
            android:layout_height="match_parent" 
            android:layout_gravity="start"
            android:layout_weight="40" 
            android:background="@android:color/white"
            android:choiceMode="singleChoice" 
            android:divider="@android:color/transparent"
            android:dividerHeight="0dp"
            tools:context=".NavigationDrawerFragment"/>
    </android.support.v4.widget.DrawerLayout>
</LinearLayout>

what is the problem with that ? While using NavigationView instead of ListView there is no problem. But I need a ListView for my app. what should I do?


回答1:


You need to call a method to close the active drawer, like DrawerLayout.closeDrawers().



来源:https://stackoverflow.com/questions/33667220/navigation-drawer-is-not-closing-while-navigation-item-is-selected

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