The following is the first few sections of a chapter from The Busy Coder's Guide to Android Development, plus headings for the remaining major sections, to give you an idea about the content of the chapter.


Implementing a Navigation Drawer

Each year brings a new design pattern in Android that takes the development community by storm. In 2011, it was the action bar. In 2012, it was ViewPager. In 2013, it was the navigation drawer.

This chapter covers that navigation drawer pattern: what it is, where you use it, and how you implement it, using a DrawerLayout class supplied by the Android Support package.

Prerequisites

Understanding this chapter requires that you have read the core chapters of this book. In addition, one section ties into the chapter on action modes.

What is a Navigation Drawer?

Complex apps often require complex navigation, to get to all of the different areas of the app. And, in many cases, that navigation is tied to nouns, reflecting different types of content, more so than verbs, reflecting operations to be performed against a particular piece of content. Verbs are actions, and can usually go in the action bar as action bar items (e.g., toolbar-style buttons). Nouns could be put in the action bar as well as items, though having a mixed bunch of nouns and verbs makes the action bar item roster inconsistent.

Back before the action bar, the “go-to” design pattern for navigation was the so-called “dashboard”:

Google IO 2010 Conference App, with Dashboard
Figure 527: Google IO 2010 Conference App, with Dashboard

But this took up the whole screen and was therefore only available as the “home” activity of an app.

The navigation drawer, or “sliding menu”, pattern has the same sort of content navigation options available in a drawer that slides out from the side of the screen:

Google+, with Open Navigation Drawer
Figure 528: Google+, with Open Navigation Drawer

The drawer can be accessed from many, if not all, activities in the app, to allow the user to get wherever they need to from wherever they happen to be.

A Simple Navigation Drawer

The preview of this section is being chased by zombies.

Alternative Row Layouts

The preview of this section is sleeping in.

Additional Considerations

The preview of this section was traded for a bag of magic beans.

What Should Not Be in the Drawer

The preview of this section was whisked away by a shark-infested tornado.

Independent Implementations

The preview of this section may contain nuts.