简体   繁体   English

选择导航项时导航抽屉未关闭

[英]Navigation drawer is not closing while navigation item is selected

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.使用 NavigationView 而不是 ListView 时没有问题。 But I need a ListView for my app.但是我的应用程序需要一个 ListView。 what should I do?我该怎么办?

您需要调用一个方法来关闭活动抽屉,例如DrawerLayout.closeDrawers()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM