单击事件关闭导航抽屉

我无法单击我的任何菜单项,我无法从右向左滑动以关闭抽屉,但是,无论何时打开并单击屏幕,它都会立即关闭。


智慧大石
浏览 140回答 1
1回答

哆啦的时光机

在BottomActivity中将此添加到您的onCreate中:&nbsp; &nbsp; NavigationView nav_view;&nbsp; &nbsp; nav_view = findViewById(R.id.nav_view);&nbsp; &nbsp;//select nav_view from activity_drawer_layout&nbsp; &nbsp; nav_view.setNavigationItemSelectedListener(this);在activity_drawer_layout.xml中,将NavigationView放在DrawerLayout的结束标记上方。<?xml version="1.0" encoding="utf-8"?><android.support.v4.widget.DrawerLayoutxmlns: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"tools:context=".DrawerLayout"android:id="@+id/DrawerLayout"><include&nbsp; &nbsp; android:id="@+id/include"&nbsp; &nbsp; layout="@layout/app_bar_nav_drawer"&nbsp; &nbsp; android:layout_width="0dp"&nbsp; &nbsp; android:layout_height="0dp" /><LinearLayout&nbsp; &nbsp; android:id="@+id/linearLayout"&nbsp; &nbsp; android:layout_width="0dp"&nbsp; &nbsp; android:layout_height="673dp"&nbsp; &nbsp; android:padding="16dp"&nbsp; &nbsp; android:orientation="vertical">&nbsp; &nbsp; <android.support.v7.widget.CardView&nbsp; &nbsp; &nbsp; &nbsp; android:layout_width="match_parent"&nbsp; &nbsp; &nbsp; &nbsp; android:layout_height="wrap_content"&nbsp; &nbsp; &nbsp; &nbsp; android:id="@+id/cv">&nbsp; &nbsp; &nbsp; &nbsp; <RelativeLayout&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_width="match_parent"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_height="wrap_content">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <TextView&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_width="wrap_content"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_height="wrap_content"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:id="@+id/name" />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <TextView&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_width="wrap_content"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_height="wrap_content"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:id="@+id/age"/>&nbsp; &nbsp; &nbsp; &nbsp; </RelativeLayout>&nbsp; &nbsp; </android.support.v7.widget.CardView></LinearLayout><android.support.v7.widget.CardView&nbsp; &nbsp; xmlns:card_view="http://schemas.android.com/apk/res-auto"&nbsp; &nbsp; android:id="@+id/cardView"&nbsp; &nbsp; android:layout_width="match_parent"&nbsp; &nbsp; android:layout_height="wrap_content"&nbsp; &nbsp; card_view:layout_constraintBottom_toBottomOf="@+id/nav_header" /><include&nbsp; &nbsp; android:id="@+id/include"&nbsp; &nbsp; layout="@layout/app_bar_nav_drawer"&nbsp; &nbsp; android:layout_width="wrap_content"&nbsp; &nbsp; android:layout_height="wrap_content" /><android.support.design.widget.NavigationView&nbsp; &nbsp; android:id="@+id/nav_view"&nbsp; &nbsp; android:layout_width="wrap_content"&nbsp; &nbsp; android:layout_height="match_parent"&nbsp; &nbsp; android:fitsSystemWindows="true"&nbsp; &nbsp; android:layout_gravity="start"&nbsp; &nbsp; android:clickable="true"&nbsp; &nbsp; android:focusable="true"&nbsp; &nbsp; android:orientation="vertical"&nbsp; &nbsp; app:headerLayout="@layout/nav_header_nav_drawer"&nbsp; &nbsp; app:menu="@menu/activity_nav_drawer_drawer" /></android.support.v4.widget.DrawerLayout>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java