CHAPTER 11
Beginner
AppBar, Toolbar, and Navigation Drawer Design
Updated: May 31, 2026
5 min read
# CHAPTER 11
AppBar, Toolbar, and Navigation Drawer Design
1. Introduction
Every great app needs a way for users to find their way around. The Top App Bar (often containing a Toolbar) is a critical UI component that displays information and actions relating to the current screen. It's where the app title lives, where search icons reside, and where the famous "Hamburger" menu icon sits to open a Navigation Drawer. In this chapter, we will design these essential top-level navigation structures.2. Learning Objectives
By the end of this chapter, you will be able to:-
Differentiate between the legacy
ActionBarand the modernToolbar.
-
Customize a
Toolbarusing XML layout files.
-
Implement an
AppBarLayoutfor scrolling behaviors.
-
Design a
NavigationViewto act as a side drawer menu.
- Build a News App navigation UI.
3. ActionBar vs Toolbar
In the past, Android provided a defaultActionBar at the top of the screen. However, it was rigid and hard to customize.
Google introduced the Toolbar. A Toolbar is just a ViewGroup that you can place *anywhere* in your XML layout, just like a LinearLayout. This gives you total control over its design, size, and content.
Step 1: To use a custom Toolbar, you must first disable the default ActionBar in your themes.xml:
xml
4. Customizing the Toolbar
Let's build a custom Toolbar in XML. We place it inside anAppBarLayout, which is a special layout designed to handle scrolling effects (like hiding the toolbar when the user scrolls down).
xml
5. Adding Menu Icons (Actions)
To add icons (like Search or Settings) to the right side of the Toolbar, you create a Menu XML file inres/menu/.
xml
You then inflate this menu in your Kotlin Activity using onCreateOptionsMenu.
6. The Navigation Drawer
The Navigation Drawer is a panel that slides in from the left edge of the screen. It is typically used for top-level navigation destinations.To implement a drawer, your entire layout must be wrapped in a DrawerLayout.
xml
7. Designing the Drawer Header
A Drawer usually has a beautiful header at the top (e.g., showing the user's profile picture and email). You design this just like any other XML layout (e.g.,nav_header.xml) and link it to the NavigationView using the app:headerLayout attribute.
8. Common Mistakes
-
Forgetting
NoActionBartheme: If you try to add a customToolbarwhile your app theme still provides a defaultActionBar, the app will crash or display two toolbars.
-
Wrong
layout_gravityin Drawer: If you don't setandroid:layout_gravity="start"on theNavigationView, the DrawerLayout will throw an exception.
9. Best Practices
- Don't overload the Drawer: The drawer should only contain top-level destinations (Home, Profile, Settings). Don't put deep, specific actions inside it.
- Use standard icons: Use familiar vector icons for your menu items so users instantly know what they do without reading the text.
10. Exercises
-
1.
Create a
nav_header.xmllayout containing anImageViewfor a profile picture and aTextViewfor an email address.
-
2.
Create a
drawer_menu.xmlwith three items: Home, Favorites, and Settings. Attach both to yourNavigationView.
11. UI Design Challenges
Challenge: Design a "Collapsing Toolbar". UseCollapsingToolbarLayout so that the app bar starts large (showing a big hero image) but shrinks down into a normal Toolbar when the user scrolls the content upwards.
12. MCQ Quiz with Answers
Question 1
What layout must wrap your entire screen to implement a sliding side menu?
Question 2
What must you change in your themes.xml to successfully use a custom XML <Toolbar>?
13. Interview Questions
-
Q: What is the structural difference between an
ActionBarand aToolbar?
-
Q: How does the
AppBarLayoutenhance the functionality of a standardToolbar?
14. FAQs
Q: Are Navigation Drawers still popular? A: Yes, but they are often replaced by Bottom Navigation for apps with 3 to 5 main destinations, as Bottom Navigation is easier to reach on tall phones. Drawers are still ideal for apps with many complex navigation options (like Gmail).15. Summary
In this chapter, we stripped away the restrictive legacy ActionBar and took full control of our top-level UI using the modernToolbar. We learned how to add action icons and built a comprehensive DrawerLayout that provides a sliding NavigationView with a custom header, giving our users a clear map of the application.