Navigation Drawer
Navigation Drawer:
Navigation Drawer is the concept of a design pattern which is a panel that looks like a sidenav which is used in the application for display of the basic navigation of applications.
It is normally located on the side of the screen being slightly off the visible part and may be opened by dragging from the right edge of the screen or clicking on the icon in the app bar that resembles a hamburger.
Example:
<!-- activity_main.xml -->
<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_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<!-- Main content layout -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- Toolbar -->
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:titleTextColor="#ffffff"
android:elevation="5dp"
android:background="#000000"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
<!-- Main Content -->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Click on three lines top left corner in toolbar"
android:textColor="@color/colorOrange"
android:textSize="22sp"
android:gravity="center"
android:padding="16dp"
android:layout_marginTop="50dp"/>
</LinearLayout>
<!-- The navigation drawer -->
<com.google.android.material.navigation.NavigationView
android:id="@+id/navigation"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="@layout/nav_header"
app:menu="@menu/nav_items"/>
</androidx.drawerlayout.widget.DrawerLayout>
<!-- nav_header.xml -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/nav_header"
android:layout_width="match_parent"
android:layout_height="160dp"
android:background="@color/colorAccent"
android:clickable="true"
android:focusable="true"
android:foreground="?attr/selectableItemBackgroundBorderless"
android:gravity="bottom"
android:orientation="vertical"
android:padding="16dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark">
<ImageView
android:id="@+id/nav_header_imageView"
android:layout_width="64dp"
android:layout_height="64dp"
android:src="@mipmap/ic_launcher_round" />
<TextView
android:id="@+id/nav_header_textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="16dp"
android:text="Android Development Tutorials"
android:textAppearance="@style/TextAppearance.AppCompat.Body1" />
</LinearLayout>
<!-- nav_items.xml -->
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:showIn="navigation_view">
<group android:checkableBehavior="single">
<item
android:id="@+id/nav_home"
android:icon="@drawable/ic_home_black_24dp"
android:title="Home" />
<item
android:id="@+id/nav_other_apps"
android:icon="@drawable/ic_music_player"
android:title="Other Apps" />
<item android:title="Others">
<menu>
<item
android:id="@+id/nav_feedback"
android:icon="@drawable/ic_feedback_black_24dp"
android:title="Feedback" />
<item
android:id="@+id/nav_share"
android:icon="@drawable/ic_share_black_24dp"
android:title="Share" />
<item
android:id="@+id/nav_rate"
android:icon="@drawable/ic_stars_black_24dp"
android:title="Rate Us" />
</menu>
</item>
</group>
</menu>