我已经在已经工作的活动上创建了导航抽屉。我将一些按钮从顶部移至导航抽屉。现在导航抽屉工作正常。它滑动并且单击侦听器也正在工作,但活动不起作用。抽屉在单击时关闭,但在活动中没有任何内容是可单击的。下面附上代码:
主要活动
<RelativeLayout 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="wrap_content"
android:layout_height="match_parent"
android:background="#fff"
tools:context="com.example.fooddelivery.Activities.MainAdminActivity">
<RelativeLayout
android:id="@+id/toolBarRL"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/btn_grad"
android:padding="10dp"
>
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/profileIv"
android:layout_width="80dp"
android:layout_height="80dp"
android:visibility="gone"
android:src="@drawable/ic_person_grey"
app:civ_border_color="@color/orange"
app:civ_border_overlay="true"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_below="@+id/profileIv"
android:layout_marginTop="50dp"
android:background="@drawable/shape_rec03"
android:orientation="horizontal"
android:padding="0dp">
<!--Service Providers-->
<TextView
android:id="@+id/tabSPTv"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_weight="1"
android:background="@drawable/shape_rec04"
android:gravity="center"
android:text="Service Providers"
android:textColor="#000000" />
<!--Orders-->
<TextView
android:id="@+id/tabUsersTv"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_weight="1"
android:gravity="center"
android:text="Users"
android:textColor="#ffffff" />
</LinearLayout>
</RelativeLayout>
<!--Service providers UI-->
<RelativeLayout
android:id="@+id/SPRL"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff"
android:layout_below="@+id/toolBarRL">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/shopsRv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_marginBottom="5dp"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:listitem="@layout/row_shop" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/usersRl"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff"
android:layout_below="@+id/toolBarRL">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/usersRv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_marginBottom="5dp"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:reverseLayout="true"
app:stackFromEnd="true"
tools:listitem="@layout/row_all_users" />
</RelativeLayout>
<include
layout="@layout/navigation_drawer_activity"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
标题
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:background="@color/orange"
android:padding="15dp"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_person_grey"
android:contentDescription="Header image"
android:id="@+id/profileIv"
android:layout_margin="10dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name"
android:id="@+id/nameTv"
android:textColor="#fff"
android:textSize="20sp"
android:layout_margin="0dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#fff"
android:text="Email"
android:id="@+id/emailTv"
android:layout_margin="10dp"
android:textSize="12sp"
/>
<TextView
android:id="@+id/phoneTv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:textSize="10sp"
android:text="0321-1234567"
/>
</LinearLayout>
工具栏
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/appL">
<androidx.appcompat.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/orange"
android:id="@+id/toolbar" />
</com.google.android.material.appbar.AppBarLayout>
</LinearLayout>
导航抽屉
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.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"
android:fitsSystemWindows="true"
android:id="@+id/drawer"
tools:openDrawer="start"
tools:context="com.example.fooddelivery.Activities.MainAdminActivity">
<include layout="@layout/tool_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<com.google.android.material.navigation.NavigationView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
android:id="@+id/navView"
app:headerLayout="@layout/header"
app:menu="@menu/navigation_seller_main">
</com.google.android.material.navigation.NavigationView>
</androidx.drawerlayout.widget.DrawerLayout>
根据模态导航抽屉的材料组件文档,使用以下模板:
<androidx.drawerlayout.widget.DrawerLayout
...
android:id="@+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:openDrawer="start">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<!-- Screen content -->
<!-- Use app:layout_behavior="@string/appbar_scrolling_view_behavior" to fit below top app bar -->
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<com.google.android.material.navigation.NavigationView
...
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start" />
</androidx.drawerlayout.widget.DrawerLayout>