为了账号安全,请及时绑定邮箱和手机立即绑定

单击事件关闭导航抽屉

单击事件关闭导航抽屉

智慧大石 2022-12-28 10:37:56
我无法单击我的任何菜单项,我无法从右向左滑动以关闭抽屉,但是,无论何时打开并单击屏幕,它都会立即关闭。
查看完整描述

1 回答

?
哆啦的时光机

TA贡献1779条经验 获得超6个赞

在BottomActivity中将此添加到您的onCreate中:


    NavigationView nav_view;


    nav_view = findViewById(R.id.nav_view);   //select nav_view from activity_drawer_layout


    nav_view.setNavigationItemSelectedListener(this);

在activity_drawer_layout.xml中,将NavigationView放在DrawerLayout的结束标记上方。


<?xml version="1.0" encoding="utf-8"?>

<android.support.v4.widget.DrawerLayout

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"

tools:context=".DrawerLayout"

android:id="@+id/DrawerLayout">


<include

    android:id="@+id/include"

    layout="@layout/app_bar_nav_drawer"

    android:layout_width="0dp"

    android:layout_height="0dp" />

<LinearLayout

    android:id="@+id/linearLayout"

    android:layout_width="0dp"

    android:layout_height="673dp"

    android:padding="16dp"

    android:orientation="vertical">


    <android.support.v7.widget.CardView

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:id="@+id/cv">


        <RelativeLayout

            android:layout_width="match_parent"

            android:layout_height="wrap_content">


            <TextView

                android:layout_width="wrap_content"

                android:layout_height="wrap_content"

                android:id="@+id/name" />


            <TextView

                android:layout_width="wrap_content"

                android:layout_height="wrap_content"

                android:id="@+id/age"/>

        </RelativeLayout>


    </android.support.v7.widget.CardView>


</LinearLayout>


<android.support.v7.widget.CardView

    xmlns:card_view="http://schemas.android.com/apk/res-auto"

    android:id="@+id/cardView"

    android:layout_width="match_parent"

    android:layout_height="wrap_content"

    card_view:layout_constraintBottom_toBottomOf="@+id/nav_header" />


<include

    android:id="@+id/include"

    layout="@layout/app_bar_nav_drawer"

    android:layout_width="wrap_content"

    android:layout_height="wrap_content" />


<android.support.design.widget.NavigationView

    android:id="@+id/nav_view"

    android:layout_width="wrap_content"

    android:layout_height="match_parent"

    android:fitsSystemWindows="true"

    android:layout_gravity="start"

    android:clickable="true"

    android:focusable="true"

    android:orientation="vertical"

    app:headerLayout="@layout/nav_header_nav_drawer"

    app:menu="@menu/activity_nav_drawer_drawer" />



</android.support.v4.widget.DrawerLayout>


查看完整回答
反对 回复 2022-12-28
  • 1 回答
  • 0 关注
  • 139 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号