点击屏幕的空白部分以关闭Android中的导航抽屉 [英] Close navigation drawer in Android by tapping on the empty portion of the screen

查看:622
本文介绍了点击屏幕的空白部分以关闭Android中的导航抽屉的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Android应用程序中有导航抽屉,其可见性由操作栏中的应用程序"图标控制.但是,我不仅需要通过点击应用程序图标来关闭抽屉,而且还需要在用户点击屏幕上的空白(未占用)部分时关闭抽屉.这是我的主要布局:

I have navigation drawer in my Android app and its visibility is controlled by the App icon in the Action Bar. However, I need to be able to close the drawer not only by tapping the app icon but also if the user taps on the empty (non-occupied) portion of the screen. This is my main layout:

<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"

android:layout_width="match_parent"
android:layout_height="match_parent">

<FrameLayout
    android:id="@+id/content_frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

<ListView
    android:id="@+id/left_drawer"
    android:layout_width="240dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:choiceMode="singleChoice"

    android:background="@color/white"
    style="@style/ListViewSeparator"/>

我不明白我需要设置哪种布局,因为当我打开导航抽屉时,它包含我的"240dp"列表视图,但是屏幕的其余部分变成了透明黑色",我正在寻找屏幕其余部分的透明黑色"布局

I don't understand which layout is the one I need to set a listener to, because when I open the navigation drawer it contains my '240dp' listview, but the rest of the screen becomes like 'transparent black', I am looking for that 'transparent black' layout which is the rest of the screen

推荐答案

找到了它:

 mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);

之前设置为LOCK_MODE_LOCKED_OPENED

这篇关于点击屏幕的空白部分以关闭Android中的导航抽屉的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆