点击屏幕的空白部分以关闭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