Join Albert Lo for an in-depth discussion in this video The navigation drawer layout, part of Android Development: Modern Android UI Design Elements.
- [Instructor] The side navigation drawer is one of the most popular UI controls, and it allows the user to quickly navigate between the major screens in the application. Here's a demo of the finished product that we're going to build for the side navigation drawer. As you can tell, the side navigation drawer is fairly easy to understand. You just have to tap on a drawer item, and it will launch either a fragment or a new activity, and that effectively navigates the user to another part of the app.
Prior to Android API 22, Android developers would have to use third-party libraries to help with implementing the side navigation drawer layout. However, as of API 22, which is Marshmallow, Google introduced a new UI control to make it easier to implement the side navigation drawer. And it is called the navigation view. One of the sample projects provided by the wizard templates in Android Studio contains a sample for the navigation drawer right out of the box.
However, one of the constraints with using the navigation view directly is that all of the items in the drawer have to be menu items. Menu items are fine for simple-use cases. However, one of the main drawbacks with menu items is that there is less control over how the nav drawer items look and feel. For instance, you cannot easily change the text color of a menu item. I mean, it can be done, but it takes a bit of code to make it work, because a menu item is not a text view.
And, furthermore, you cannot change the underline. So, for instance, if I wanted to change the color or the shading of this underline item here, I cannot do that with a menu item. And because a menu item is not a text view, you don't have all of the features available to you easily in a text view. As an aside, the navigation view is itself a custom view, and contains many of the elements that we will learn about more in later chapters.
For now, we will learn about how to work with this custom view from a user perspective. Next, we will look at how to customize the navigation drawer layout to address some of the issues that I've talked about here, and give us better control of the UI for a drawer item.
- Creating a custom layout with XML
- Setting up OnClick handlers
- Making API calls
- Creating custom views
- Implementing ViewHolder objects
- Signing certificates
- Adding a checkbox