Navigation menus dispatch events that you can handle with a bit of Kotlin code. In this video, learn how to react to navigation menu events and manage the sliding navigation drawer.
- [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, …
Looking for study partners?Join the Associate Android Developer Exam study group
The Android app architecture constantly evolves. The introduction of the Kotlin programming language, new form factors such as Chromebooks, and reusable architecture components have made it faster and easier than ever to build high-quality Android apps. It is imperative that developers understand what the latest tools and recommendations are and how to use them to build out their applications. In this course, instructor David Gassner explains how to build an Android app that uses Kotlin instead of Java, add navigation functionality, and leverage the most useful architecture components such as LifecycleObserver, ViewModel, and LiveData, to create apps that are robust and easy to maintain over time.
- Handling lifecycle events
- Handling view events
- Updating display from new data
- Adding ViewModels to activities
- Subscribing to changes in LiveData values
- Adding a new launcher activity
- Starting activities with explicit intents
- Sharing data with implicit intents
- Adding a navigation drawer
- Adding a header to a navigation drawer
- Handling navigating drawer menu events