Home

Awesome

DEPRECATED

There will (probably) be no more active development of this library. See NavigationView which is available as part of the Android Design Support library. This widget should be sufficient for most of your needs.

http://developer.android.com/reference/android/support/design/widget/NavigationView.html

Material Navigation Drawer

<img src="./navigation-drawer-sample/src/main/res/mipmap-xxhdpi/ic_launcher.png" align="right" style="margin-left: 1em;"/>

Navigation Drawer according to Material Design spec.

Contains native and support fragments of expanded and collapsed navigation list for use with DrawerLayout or Chiu-Ki Chan's CrossFadeSlidingPaneLayout (included).

The library is now available from API 4.

Screenshots

Lollipop, light theme, custom background  Lollipop, dark, theme, plain background

Kitkat, light theme, plain background  Kitkat, dark theme, custom background

Lollipop Tablet Expanded  Lollipop Tablet Collapsed

How to get the library?

To use this library add the following to your module's build.gradle:

dependencies {
    compile 'net.xpece.material:navigation-drawer:0.7.7@aar'
}

Additionally this library depends on

Proguard setup:

-dontwarn net.xpece.material.navigationdrawer.**

Default behavior

Customization

The drawer has too big right margin!

As of support-v4 library <s>21.0.3</s> 22.1.1 there is a hardcoded margin of 64dp in a DrawerLayout. Use NavigationDrawerUtils.fixMinDrawerMargin(DrawerLayout) to remove this limitation. Use this right after you obtain a drawer layout instance typically in Activity.onCreate(Bundle). Why is this an issue? Specs say the margin should be only 56dp on phones.

I want the drawer to have a standard width!

To set proper drawer width according to specs call NavigationDrawerUtils.setProperNavigationDrawerWidth(View) on your instance of NavigationDrawerFragment.getView(). This is not handled automatically to allow developers to reuse the fragment outside of DrawerLayout with custom width.

The width will be one of the following:

I want the drawer to have a different background!

You can modify the navigation drawer background by accessing one of NavigationDrawerFragment.setBackground*() methods. Please note that the same background will be used for the pinned section. So if you use the pinned section either use a fully opaque color for background or follow this SO post to align your bitmap to bottom. The background is not scrolling (which is not very "material design").

How do I build sections?

NavigationSectionDescriptor

How do I build items?

BaseNavigationItemDescriptor

SimpleNavigationItemDescriptor extends BaseNavigationItemDescriptor

How do I make custom items?

Extend either BaseNavigationItemDescriptor or AbsNavigationItemDescriptor. Both require you to implement method getLayoutId() which returns your custom layout resource ID. You also need to implement you own loadInto(View, boolean) method which is analogous to adapter's getView(...). Optionally you may override onViewCreated(View).

AbsNavigationItemDescriptor handles only selected background. See the ToggleNavigationItemDescriptor in sample project.

BaseNavigationItemDescriptor allows you to use all the good stuff described in previous section. Your custom layout is required to have a @id/icon image view and a @id/text text view. It's intended for cases where you need a custom view on the right side of the item (such as in SimpleNavigationItemDescriptor).

How do I employ partially visible collapsed navigation (like Gmail on tablets)?

Please see the example project, mainly res/layout-sw600dp/activity_main.xml and MainActivity.java. Only descriptors which implement GraphicNavigationItemDescriptor will be painted (both base and simple descriptors comply).

Changelog

0.7.7

0.7.6

0.7.5

0.7.4

0.7.2

0.7.1

0.7.0

0.6.0

0.5.7

0.5.6

0.5.5

0.5.4

0.5.3

0.5.2

0.5.1

0.4.3

0.3.0 Deleted

0.2.2 Deleted

0.2.1 Deleted

0.1.1 Deleted

Work TBD

License

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.