- Notifications
You must be signed in to change notification settings - Fork0
The flexible, easy to use, all in one drawer library for your Android project.
License
12bay/MaterialDrawer
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Does your applicationcontain a Drawer? Do you want to have itup and running in less than 5 minutes? Do you want your drawer to follow theAndroid Design Guidelines?Do you haveprofiles? Do you needflexibility? Is Google's navigation Drawer of thedesign support not enough for you? Do you want asimple and easy to understand api?
If any (or all) of these questions seem familiar, theMaterialDrawer is the perfect library for you.
Never waste your time again.It provides you with the easiest possible implementation of a navigation drawer for your application.There is a Header with profiles (AccountHeader), aMiniDrawer for Tablets (like Gmail), providecustom DrawerItems,custom colors,custom themes, ...No limits for customizations.
- the easiest possible integration
- integrate in less than5 minutes
- compatible down toAPI Level 14
- includes anAccountSwitcher
- quick and simple api
- follows theGoogle Material Design Guidelines
- usevector (.svg) icons andicon fonts via theAndroid-Iconics integration
- Google Material Design Icons, GoogleMaterial Community Design Icons, FontAwesome and more
- comes with variousthemes which help to get your own themes clean
- modify the colors on the go
- uses the AppCompat support library
- comes with multiple default drawer items
- based on aRecyclerView
- RTL support
- Gmail likeMiniDrawer
- expandable items
- badge support
- define custom drawer items
- tested andstable
- sticky footer or headers
- absolutely NO limits
If you upgrade from < 5.9.0 follow theMIGRATION GUIDE
You can try it out hereGoogle Play (wall:splash an open source application which uses this drawer implementation). Or you try theSample Application
You can find some frequently asked questions and other resources in theWIKI / FAQ site.
compile('com.mikepenz:materialdrawer:5.9.5@aar') {transitive=true}
newDrawerBuilder().withActivity(this).build();
Great. Your drawer is now ready to use.
//if you want to update the items at a later time it is recommended to keep it in a variablePrimaryDrawerItemitem1 =newPrimaryDrawerItem().withIdentifier(1).withName(R.string.drawer_item_home);SecondaryDrawerItemitem2 =newSecondaryDrawerItem().withIdentifier(2).withName(R.string.drawer_item_settings);//create the drawer and remember the `Drawer` result objectDrawerresult =newDrawerBuilder() .withActivity(this) .withToolbar(toolbar) .addDrawerItems(item1,newDividerDrawerItem(),item2,newSecondaryDrawerItem().withName(R.string.drawer_item_settings) ) .withOnDrawerItemClickListener(newDrawer.OnDrawerItemClickListener() {@OverridepublicbooleanonItemClick(Viewview,intposition,IDrawerItemdrawerItem) {// do something with the clicked item :D } }) .build();
//set the selection to the item with the identifier 1result.setSelection(1);//set the selection to the item with the identifier 2result.setSelection(item2);//set the selection and also fire the `onItemClick`-listenerresult.setSelection(1,true);
By default, when a drawer item is clicked, it becomes the new selected item. If this isn't the expected behavior,you can disable it for this item usingwithSelectable(false)
:
newSecondaryDrawerItem().withName(R.string.drawer_item_dialog).withSelectable(false)
//modify an item of the draweritem1.withName("A new name for this drawerItem").withBadge("19").withBadgeStyle(newBadgeStyle().withTextColor(Color.WHITE).withColorRes(R.color.md_red_700));//notify the drawer about the updated element. it will take care about everything elseresult.updateItem(item1);//to update only the name, badge, icon you can also use one of the quick methodsresult.updateName(1,"A new name");//the result object also allows you to add new items, remove items, add footer, sticky footer, ..result.addItem(newDividerDrawerItem());result.addStickyFooterItem(newPrimaryDrawerItem().withName("StickyFooterItem"));//remove items with an identifierresult.removeItem(2);//open / close the drawerresult.openDrawer();result.closeDrawer();//get the reference to the `DrawerLayout` itselfresult.getDrawerLayout();
// Create the AccountHeaderAccountHeaderheaderResult =newAccountHeaderBuilder().withActivity(this) .withHeaderBackground(R.drawable.header).addProfiles(newProfileDrawerItem().withName("Mike Penz").withEmail("mikepenz@gmail.com").withIcon(getResources().getDrawable(R.drawable.profile))) .withOnAccountHeaderListener(newAccountHeader.OnAccountHeaderListener() {@OverridepublicbooleanonProfileChanged(Viewview,IProfileprofile,booleancurrentProfile) {returnfalse;}}).build();//Now create your drawer and pass the AccountHeader.ResultnewDrawerBuilder() .withAccountHeader(headerResult)//additional Drawer setup as shown above ... .build();
The MaterialDrawer comes with thecore
of theAndroid-Iconics library. This allows you to create yourDrawerItems
with an icon from any font.
Choose the fonts you need.Available Fontsbuild.gradle
compile'com.mikepenz:google-material-typeface:x.y.z@aar'//Google Material Iconscompile'com.mikepenz:fontawesome-typeface:x.y.z@aar'//FontAwesome
java
//now you can simply use any icon of the Google Material Icons fontnewPrimaryDrawerItem().withIcon(GoogleMaterial.Icon.gmd_wb_sunny)//Or an icon from FontAwesomenewSecondaryDrawerItem().withIcon(FontAwesome.Icon.faw_github)
newDrawerBuilder().withActivity(this).withTranslucentStatusBar(false) .withActionBarDrawerToggle(false).addDrawerItems(//pass your items here).build();
Drawerresult =newDrawerBuilder().withActivity(this).withToolbar(toolbar).addDrawerItems(//pass your items here).build();newDrawerBuilder().withActivity(this) .addDrawerItems(//pass your items here ) .withDrawerGravity(Gravity.END) .append(result);
The MaterialDrawer supports fetching images from URLs and setting them for the Profile icons. As the MaterialDrawer does not contain an ImageLoading librarythe dev can choose his own implementation (Picasso, Glide, ...). This has to be done, before the first image should be loaded via URL. (Should be done in the Application, but any other spot before loading the first image is working too)
//initialize and create the image loader logicDrawerImageLoader.init(newAbstractDrawerImageLoader() {@Overridepublicvoidset(ImageViewimageView,Uriuri,Drawableplaceholder) {Picasso.with(imageView.getContext()).load(uri).placeholder(placeholder).into(imageView); }@Overridepublicvoidcancel(ImageViewimageView) {Picasso.with(imageView.getContext()).cancelRequest(imageView); }/* @Override public Drawable placeholder(Context ctx) { return super.placeholder(ctx); } @Override public Drawable placeholder(Context ctx, String tag) { return super.placeholder(ctx, tag); } */});
An implementation withGLIDE can be found in the sample application
If you use the included ActionBarDrawerToggle you can switch between back-arrow or hamburger-iconwith the following code snippet. (Please note that the order of these lines matter)
result.getActionBarDrawerToggle().setDrawerIndicatorEnabled(false);getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(false);result.getActionBarDrawerToggle().setDrawerIndicatorEnabled(true);
TheMaterialDrawer requires anAppCompat
theme or a derivative theme like theMaterialDrawerTheme
s as base. It is highly recommended to use one of the provided themes. They all use theAppCompat
theme as parent and define the color values for the drawer.
NOTE: The theme states ActionBar and not NoActionBar like the Appcompat style
- MaterialDrawerTheme (extends Theme.AppCompat.NoActionBar)
- MaterialDrawerTheme.TranslucentStatus
- MaterialDrawerTheme.ActionBar (extends Theme.AppCompat)
- MaterialDrawerTheme.ActionBar.TranslucentStatus
- MaterialDrawerTheme.Light (extends Theme.AppCompat.Light.NoActionBar)
- MaterialDrawerTheme.Light.TranslucentStatus
- MaterialDrawerTheme.Light.ActionBar (extends Theme.AppCompat.Light)
- MaterialDrawerTheme.Light.ActionBar.TranslucentStatus
- MaterialDrawerTheme.Light.DarkToolbar (extends Theme.AppCompat.DarkActionBar) (disabled the ActionBar)
- MaterialDrawerTheme.Light.DarkToolbar.TranslucentStatus
- MaterialDrawerTheme.Light.DarkToolbar.ActionBar (extends Theme.AppCompat.DarkActionBar)
- MaterialDrawerTheme.Light.DarkToolbar.ActionBar.TranslucentStatus
If you don't use one of the provided styles you have to add the style values to your style. Here's a simple sample.This is the same as the Custom style just with a parent likeparent="Theme.AppCompat.Light.DarkActionBar"
Create your custom style and use one of the provided themes as parent. If you don't need a custom theme see the next section, how you can set the colors just by overwriting the original colors.
<stylename="CustomTheme"parent="MaterialDrawerTheme"><!-- ...and here we setting appcompat’s color theming attrs--> <itemname="colorPrimary">@color/material_drawer_primary</item> <itemname="colorPrimaryDark">@color/material_drawer_primary_dark</item> <itemname="colorAccent">@color/material_drawer_accent</item><!-- MaterialDrawer specific values--> <itemname="material_drawer_background">@color/material_drawer_background</item> <itemname="material_drawer_primary_text">@color/material_drawer_primary_text</item> <itemname="material_drawer_primary_icon">@color/material_drawer_primary_icon</item> <itemname="material_drawer_secondary_text">@color/material_drawer_secondary_text</item> <itemname="material_drawer_hint_text">@color/material_drawer_hint_text</item> <itemname="material_drawer_divider">@color/material_drawer_divider</item> <itemname="material_drawer_selected">@color/material_drawer_selected</item> <itemname="material_drawer_selected_text">@color/material_drawer_selected_text</item> <itemname="material_drawer_header_selection_text">@color/material_drawer_header_selection_text</item> </style>
No need to create a custom theme. Just set these colors (or some of them) and you have your own style.
<!-- Material DEFAULT colors--> <colorname="material_drawer_primary">#2196F3</color> <colorname="material_drawer_primary_dark">#1976D2</color> <colorname="material_drawer_primary_light">#BBDEFB</color> <colorname="material_drawer_accent">#FF4081</color><!-- OVERWRITE THESE COLORS FOR A LIGHT THEME--><!-- MaterialDrawer DEFAULT colors--> <colorname="material_drawer_background">#F9F9F9</color><!-- Material DEFAULT text / items colors--> <colorname="material_drawer_primary_text">#DE000000</color> <colorname="material_drawer_primary_icon">#8A000000</color> <colorname="material_drawer_secondary_text">#8A000000</color> <colorname="material_drawer_hint_text">#42000000</color> <colorname="material_drawer_divider">#1F000000</color><!-- Material DEFAULT drawer colors--> <colorname="material_drawer_selected">#E8E8E8</color> <colorname="material_drawer_selected_text">#2196F3</color> <colorname="material_drawer_header_selection_text">#FFF</color><!-- OVERWRITE THESE COLORS FOR A DARK THEME--><!-- MaterialDrawer DEFAULT DARK colors--> <colorname="material_drawer_dark_background">#303030</color><!-- MaterialDrawer DEFAULT DARK text / items colors--> <colorname="material_drawer_dark_primary_text">#DEFFFFFF</color> <colorname="material_drawer_dark_primary_icon">#8AFFFFFF</color> <colorname="material_drawer_dark_secondary_text">#8AFFFFFF</color> <colorname="material_drawer_dark_hint_text">#42FFFFFF</color> <colorname="material_drawer_dark_divider">#1FFFFFFF</color><!-- MaterialDrawer DEFAULT DARK drawer colors--> <colorname="material_drawer_dark_selected">#202020</color> <colorname="material_drawer_dark_selected_text">@color/material_drawer_primary</color> <colorname="material_drawer_dark_header_selection_text">#FFF</color>
//just use this with the Drawer.withSelectedItem(-1)
The MaterialDrawer will display your activity as FullScreen. Starting with API 19theadjustResize
works different then. This is default Android behavior.This is a big issue for a lot of devs so i've created a helper which "fixes" this issue.(It is recommend to just enable it for activities / fragments which need it)
.keyboardSupportEnabled(activity,enabled)
A additional workaround is to disable the translucent StatusBar (This will break thedrawer to be displayed under the StatusBar)..withTranslucentStatusBar(false)
You can read about this here:mikepenz#95,mikepenz#183,mikepenz#196
As the MaterialDrawer will just create a normal DrawerLayout (with some magic around it) everything a normalDrawerLayout can do is also available in the MaterialDrawer.
//get the DrawerLayout from the DrawerDrawerLayoutdrawerLayout =result.getDrawerLayout();//do whatever you want with the Drawer. Like locking it.drawerLayout.setDrawerLockMode(intlockMode);//or (int lockMode, int edgeGravity)
MaterialDrawer allows you to use a compatible implementation of MaterialDrawer.Please note that the provided layout must follow the same structure as theMaterialDrawer
internal one.
Start by copying thematerial_drawer.xml
file inside your project, and replaceandroid.support.v4.widget.DrawerLayout
with the fully qualified name of your class(com.yourapp.com.ui.CustomDrawerLayout
for example). Please note that your class must extend the original DrawerLayout.
You'll then be able to use this custom class:
builder.withDrawerLayout(R.layout.material_drawer);
Thanks to @zsmb13 there's now an (in)official Kotlin DSL wrapper for the MaterialDrawerhttps://github.com/zsmb13/MaterialDrawerKt
(feel free to send me new projects)
- wall:splash
- GitSkarios
- Screener
- Meldmail
- Academic Schedule
- Strength
- Sprit Club
- FitHub
- StickyNotes
- Smartphone Italia
- MLManager
- Hold'Em Poker Manager
- Fimpl
- +UEA
- PixCell8
- TS3 Viewer for TeamSpeak 3
- Teacher Gradebook
- Tabe3 News Reader
- Facepunch Droid
- World Tourist Attractions
- HipCar
- AS Sales Management
- Sporza Voetbal
- Atmosphere
- Slidechat
- Fitness Challenge
- European Capital of Culture - Pafos2017 official app
- I'm Reading Quran - Kur'an Okuyorum
- Makota Money Manager
- Companion for Band
- Chisme for Sensu
- Recipedia
- Right Сourse - ruble course
- Gameru
- Boost for reddit
- Touch for Facebook
- Calendula
- MyTimes
- VoIP By Antisip
Mirosław Stanek -GitHub
- For his InstaMaterial concept and the idea of inflating the drawerLayoutInstaMaterial Concept
Lunae Luman -Behance for the Header Image
Copyright 2016 Mike PenzLicensed 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.0Unless required by applicable law or agreed to in writing, softwaredistributed 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 andlimitations under the License.
About
The flexible, easy to use, all in one drawer library for your Android project.
Resources
License
Stars
Watchers
Forks
Packages0
Languages
- Java100.0%