Read complete story

Implementation of mike penz’s MaterialDrawer Library for Navigation View

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:[email protected]  ,  compile ‘com.mikepenz:fontawesome-typeface:[email protected]’  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

. . .

Comments (6)

Add Your Comment

  • Oliver Bob
    Please provide an example project for this tutorial, that would be much useful.
    • Shubham Agarwal
      Hi Oliver checkout the https://github.com/mikepenz/MaterialDrawer library. The docs and examples are easy to understand and implement. Also you will get the idea of many related view’s implementation that is provided by the library.
      • Oliver Bob
        Hi Shubham. I was able to create a new project for the lack of https://uploads.disquscdn.com/images/344314be192d19c895064e1c4b11de4ef3e351a06ffbf6a7c14ab33ec39fc8cf.png information in the web about Mike’s library. But it still uses his drawer:

        Collapsing toolbar with crossfade, searchbar and a extended actionbutton, plus the latest slider with pinch zoom which I implemented early at dawn before I finally went to sleep. 🙂

        I needed to overcome the limitations of a fairly recent obsession: the webview, that I was forced to approach material design beginning with this drawer.

        I’m only two weeks in Android development, but I know java for quit a long time and I haven’t tried it for years. I quit java when I realized that there was yet little support for distribution of java enabled phones around 2007 at least in my country, just about the time when Android was yet a company (which I haven’t heard yet back then) and the expense to do it was too high.

        But today, Android Studio provides many better promises for android applications than what was then available for mobile devices in Netbeans, even years later, while PHP and javascript was my haven.

        • Shubham Agarwal
          Yes true, Android Studio is now the official IDE for Android Application development. Our team is currently not using Mike’s library, we are using a custom one right now.
          There is a good community monitored by Mike himself https://gitter.im/mikepenz/MaterialDrawer you should really check out if there is any problem in using MaterialDrawer library.
          It was nice talking to you.
  • Abhinav Nagani
    Could you provide us with the complete source code?
  • css.php
    Hire Us!
    Brief us about your requirements and we'll get back to you.
    Woo! Hooy!
    We have just recieved your project brief and our expert will contact you shortly.
    Send Again
    Close