A toggle button gives the user a visual indicator that a navigation drawer is available. In this video, add components and code to display a toggle button in an action bar.
- [Instructor] I want to display a toggle button … in the activities top corner … that the user can press … to open the navigation drawer. … My first step is to refactor my main activity layout … and wrap the the constraint layout … in another set of components. … Let's take a look at the file activity_dice.xml. … This file's root element is something called … a coordinator layout. … It contains an app bar layout which contains a toolbar. … These components are designed to work with … the navigation drawer so I'm going to select … and copy everything starting from … the coordinator layout to right above the include statement. … And then I'll come back to activity_main.xml … and I'll paste it right here before the constraint layout. … Then I'll go down to the bottom of the file … and I'll type a less-than character and a slash, … and android studio auto-completes that to … the end tag for the coordinator layout. … The constraint layout is no longer the root element … so I don't need these name space declarations. …
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