I'm using Bottom App Bar in my app as a navigational component. When an item of Navigation Drawer (appearing from bottom) is clicked, Navigation Drawer is supposed to be closed, but it is not. When navigation item of Navigation Drawer is clicked, the related fragment is opened, but Navigation Drawer (of Bottom App Bar) still appears.
I have tried to use DrawerLayout and drawerLayout.closeDrawer(Gravity.LEFT) but it does not work.
Here is the layout:
<?xml version="1.0" encoding="utf-8"?>
<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:id="@+id/drawerView"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.drawerlayout.widget.DrawerLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/drawerLayout"
tools:openDrawer="left">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.navigation.NavigationView
android:id="@+id/navigation_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:headerLayout="@layout/nav_header_layout"
app:menu="@menu/bottom_nav_drawer_menu" >
</com.google.android.material.navigation.NavigationView>
</RelativeLayout>
</androidx.drawerlayout.widget.DrawerLayout>
</RelativeLayout>
Here is the code part at which IDE gives error:
navigation_view.setNavigationItemSelectedListener {
drawerLayout.closeDrawer(Gravity.LEFT)
...
return@setNavigationItemSelectedListener true
}
The error below occurs:
java.lang.IllegalArgumentException: No drawer view found with gravity LEFT
I have tried the solutions at the link below, but they did not work: