Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get sidenav from using bottom navigation bar in android?

I want to develop an app where I will use bottom navigation bar and when user will choose the option item it would show the side bar like the following image that comes from either left or right side, but the option button will be in bottom navbar.

Navigation bar:

enter image description here

like image 694
Emon Hossain Munna Avatar asked Oct 16 '22 00:10

Emon Hossain Munna


1 Answers

First you have to create a Navigation View and bottom navigation bar.

NavigationView

<com.google.android.material.navigation.NavigationView
    android:id="@+id/navigationView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:headerLayout="@layout/drawer_header"
    app:menu="@menu/menu_drawer"
    android:layout_gravity="start"/>

Bottom Navigation Bar

<com.google.android.material.bottomnavigation.BottomNavigationView
            android:id="@+id/bottomNavigation"
            android:layout_width="match_parent"
            android:layout_height="55dp"
            style="@style/Widget.MaterialComponents.BottomNavigationView.Colored"
            android:layout_alignParentBottom="true"
            app:menu="@menu/bottom_navigation_menu"
            android:background="@color/colorPrimaryDark"
            app:itemTextColor="@color/white"
            app:labelVisibilityMode="labeled"/>

Now to open drawer you have to set your drawer layout (which will be the parent layout) inside setOnNavigationItemSelectedListener like this

bottomNavigation.setOnNavigationItemSelectedListener{
      when(it.itemId){
          R.id.your_bottom_menu_selected_id->{
                drawer_layout_id.openDrawer(navigationView)
          }
      }
}
like image 142
Chirag Bargoojar Avatar answered Oct 18 '22 23:10

Chirag Bargoojar