本文介绍了选择导航项目时,导航抽屉未关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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>

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

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?

推荐答案

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

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

这篇关于选择导航项目时,导航抽屉未关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 04:02