Android Design Library: Navigation View

The navigation view is simple. It's usually used in the drawer layout. It shows a list of menu items as defined in XML and allows you to specify a header.


The menu attribute links to a normal menu. And the headerLayout points to a layout which should really be a fragment within if you're doing anything jazzy.

If you enable to checkable attribute on your menu items, they stay highlighted after pressed, which is very nice in a drawer layout, obviously.

The menu items can also have an app:actionLayout attribute, and a layout will be placed on the hard right of the menu. Useful for unread counts and so on and so forth.

To do something when the navigation view's menu items are pressed, a normal listener is used. In our case we'll close our navigation drawer.

mNavigationView = (NavigationView) findViewById(;
mNavigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
    public boolean onNavigationItemSelected(MenuItem item) {
        return true;
android android-navigationview

Edit on github
comments powered by Disqus
Click me