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

时间:2015-11-12 08:34:29

标签: android listview navigation-drawer

我正在创建一个导航抽屉。当我在导航栏中选择列表项时,抽屉没有关闭。这是我的代码

<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>

那有什么问题?使用NavigationView而不是ListView时没有问题。但我需要一个ListView为我的应用程序。我该怎么办?

1 个答案:

答案 0 :(得分:2)

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