Add the Navigation Drawer

We likely won’t need any additional dependencies here for the nav drawer since we added the androidx.navigation library last chapter and apps now by default include the Material Design Components library. If either are missing, though, add them now. We can then jump over to activity_main.xml to add in the nav drawer.

Update activity_main.xml

From a UI perspective, we’re adding in the nav drawer to our existing MainActivity layout, and we’re additionally going to be changing the layout a decent amount. The parent view of the screen is now going to be a <DrawerLayout> with a <Toolbar> and a <FragmentContainerView> inside:

 <androidx.drawerlayout.widget.DrawerLayout
  xmlns:android=​"http://schemas.android.com/apk/res/android" ...

Get Kotlin and Android Development featuring Jetpack now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.