javaandroidxmlandroid-studioandroid-layout

Upon creating navigation drawer, the activity/ scroll view beneath it is not working


I have created navigation drawer on an already working activity. I moved some buttons from top to navigation drawer. Now navigation drawer is working fine. It slides and click listener is also working but the activity is not working. drawer closes on clicking but on the activity nothing is clickable. Below is the code attached:

Main activity

   <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>

Header

    <?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>

Toolbar

    <?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>

Navigation drawer

    <?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>

Solution

  • According to the material components documentation for modal navigation drawer use the following template:

    <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>