Я поделился следующим кодом ниже.Вы должны поместить значок меню гамбургера для Nav Drawer на панели инструментов и NavigationView внутри DrawerLayout, у которого есть дочерний объект (ListView, RecyclerView, ExpandableListView и т. Д.), Который должен быть заполнен программно, или вы можете просто установить статические элементы в NavigationView, установивменю в NavigationView.Надеюсь, это поможет.Спросите, если у вас есть еще вопросы.
<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"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorActivityBackground"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true"
android:layoutDirection="locale"
android:orientation="vertical"
android:textDirection="locale">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.appcompat.widget.Toolbar
android:id="@+id/topbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
app:contentInsetEnd="0dp"
app:contentInsetLeft="0dp"
app:contentInsetRight="0dp"
app:contentInsetStart="0dp"/>
</RelativeLayout>
</FrameLayout>
<com.google.android.material.navigation.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
android:maxWidth="320dp">
<ExpandableListView
android:id="@+id/navList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
android:background="@color/white"
android:groupIndicator="@null" />
</com.google.android.material.navigation.NavigationView>
</androidx.drawerlayout.widget.DrawerLayout>