From the course: Android Development Essential Training: App Architecture with Kotlin

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Handle navigation drawer menu events

Handle navigation drawer menu events - Android Tutorial

From the course: Android Development Essential Training: App Architecture with Kotlin

Start my 1-month free trial

Handle navigation drawer menu events

- [Instructor] Handling navigation to your events is very similar to handling options menu events but, there is a little bit more work involved. In addition to reacting to the events, you're responsible for controlling what happens with the visual drawer. First, I'm going to need references to some view objects in the layout. The drawer layout will have to be accessible from all of my functions. So, I'll declare that as a property. I'll start with private val, I'll name the property drawerLayout and I'll use by lazy. And here, I'll call findViewById and I'll pass in the id R.id.drawer_layout. I'll declare the type of the view with the diamond operator and pass in DrawerLayout. So now, that variable will be initialized the first time I reference it. The other variables will only be accessed in the onCreate function. So I'll declare those as local variables. The first one will be called navView and I'll call findViewById, I'll set the type to NavigationView, and the resource id to…

Contents