Implementation of mike penz’s MaterialDrawer Library for Navigation View

Updated 14 December 2016

Save
The flexible, easy to use, all in one drawer library for your Android project.

Yes that’s true.  But there are still shortage of community which provide resources and relavent information about this Material Drawer Library.

In this blog We are going to implement this library in our project. And later we will see how we can tailor the flow as per our application requirement.

 

Demo

You can download the complete sample application from here.

 

Setup

 

1. Provide the gradle dependency

note: add transitive dependencies by setting transitive = true for the material drawer dependency. This will add all the relevant dependency required by the material drawer library.

Also there are some other dependency that we can add to speed up the implementation:

 compile ‘com.mikepenz:google-material-typeface:2.2.0.1@aar’  ,  compile ‘com.mikepenz:fontawesome-typeface:4.4.0.1@aar’  are the GitHub libraries that maintain Google recommended  material based icons. This will boost our development process without worrying  about the icon required.

We have used Picasso as a image loading and caching library.

 

2.   Initialize and create the image loader logic

 Note: Image loading is done in picasso but it can be change to any library.

 

3.   Create a few sample profile

Note: IProfile  is the interface that can be used to display multiple type of profiles based on the requirement.

Here  we have passed the ProfileDrawerItem object which is used to display the profile as a  drawer item of the Drawer.

We can set the icon from URL ,Drawable , DrawableRes or Bitmap.

Here Identifier is used to identifying a particular element. This is usually used OnDrawerItemClickListener to identify which drawer item has been clicked.

 

4.   Create the AccountHeader

Note: AccountHeaderBuilder class allow up to create a header of the drawer. We can create our custom header or use among the available header files.

You can change the header by using withAccountHeader(R.layout.myHeaderView). Also to set compact header  layout use withCompactStyle(true).

Here withOnAccountHeaderListener all the profile changed events related to AccountHeader are managed.

 

Screenshot_2016-04-15-22-04-26

 

5.   Create the drawer

Note: Here we have added multiple type of drawer items namely PrimaryDrawerItem, SectionDrawerItem, ExpandableDrawerItem and like that. Check the main drawer for all types of Drawer items provideded by the Material Drawer library

Here withOnDrawerItemClickListener handles all the drawer items click events related to Drawer.

Also,  .withAccountHeader(headerResult) automatically sets the AccountHeader that we created earlier for the header.

That’s all folks. Stay updated.

Important Links:

https://github.com/mikepenz/MaterialDrawer

https://gitter.im/mikepenz/MaterialDrawer

author
. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


6 comments

  • Oliver Bob
    • Shubham Agarwal
      • Oliver Bob
        • Shubham Agarwal
  • Abhinav Nagani
    • aastha gupta
  • Start a Project


      Message Sent!

      If you have more details or questions, you can reply to the received confirmation email.

      Back to Home