1

I have a bottom bar which consists of 4 fragments. Fragment A, B, C, and D. I wanted navigation drawer in fragment A, so I implemented successfully. But the problem is whenever I am opening the drawer, the bottom bar comes in front as it is in the activity layout not in that fragment. How to put the bottom bar behind the navigation drawer when it is open?

frag_A

   <?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:id="@+id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white">

<com.google.android.material.navigation.NavigationView
    android:id="@+id/nav_view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:fitsSystemWindows="false"
    android:layout_gravity="start"
    app:headerLayout="@layout/navigation_header"
     />



<androidx.coordinatorlayout.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <include layout="@layout/toolbar" />

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_marginEnd="16dp"
        android:layout_marginBottom="66dp"
        android:background="@color/colorPrimaryDark"
        android:backgroundTint="@color/colorPrimaryDark"
        android:scaleType="center"
        android:src="@drawable/post"
        app:elevation="6dp"
        app:maxImageSize="25dp"
        app:pressedTranslationZ="12dp" />


    <androidx.core.widget.NestedScrollView
        android:id="@+id/scrollview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/appbar"
        android:background="@color/white"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">


        <include layout="@layout/content_main">

        </include>

    </androidx.core.widget.NestedScrollView>

 </androidx.coordinatorlayout.widget.CoordinatorLayout>


 </androidx.drawerlayout.widget.DrawerLayout>

activity_main

  <?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout 
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:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white">

<FrameLayout
    android:id="@+id/frame_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />


<com.google.android.material.bottomnavigation.BottomNavigationView
    android:id="@+id/navigation"
    style="@style/BottomNavigationView"
    android:layout_width="match_parent"
    android:layout_height="55dp"
    android:layout_gravity="bottom"
    android:background="@drawable/rectanle_bg_bottom"
    android:foreground="?attr/selectableItemBackground"
    android:theme="@style/BottomNavigationTheme"
    app:itemBackground="@color/white"
    app:itemIconSize="17dp"
    app:itemIconTint="@drawable/bottom_navigation_selector"
    app:itemTextColor="@color/color_selector"
    app:labelVisibilityMode="labeled"
    />

  • 1
    You can't really do that, with that setup, since the `BottomNavigationView` is in the `Activity`'s layout. You could move the `DrawerLayout` to the `Activity`, and just lock it closed for all `Fragment`s except the one. Btw, the `` needs to be listed last in the `` in order for it to receive touch events properly. – Mike M. Nov 25 '19 at 23:29

1 Answers1

0

This may helps you

You have to add navdrawer in activity and access it from fragment by ((HomeActivity) getActivity()).unlockDrawer();

Syed Hasan
  • 161
  • 1
  • 5
  • If you are answering a 2 year old question please try to explain the reasoning behind your answer in detail and maybe some code, otherwise this looks more like a quick comment. You can see the same was said in a comment 2 years ago. – JonZarate Jul 16 '21 at 11:49