Convert Figma logo to code with AI

mikepenz logoMaterialDrawer

The flexible, easy to use, all in one drawer library for your Android project. Now brand new with material 2 design.

11,674
2,049
11,674
9

Top Related Projects

图片选择库,单选/多选、拍照、裁剪、压缩,自定义。包括视频选择和录制。

😍 A beautiful, fluid, and extensible dialogs API for Kotlin & Android.

Side menu with some categories to choose.

swipe display drawer with flowing & bouncing effects.

DrawerLayout-like ViewGroup, where a "drawer" is hidden under the content view, which can be shifted to make the drawer visible.

Android Floating Action Button based on Material Design specification

Quick Overview

MaterialDrawer is a flexible and easy-to-use Drawer library for Android applications. It provides a customizable navigation drawer implementation that follows Material Design guidelines, offering a wide range of features and customization options to enhance the user interface and navigation experience in Android apps.

Pros

  • Extensive customization options for drawer items, headers, and footers
  • Seamless integration with Material Design components and themes
  • Regular updates and active maintenance by the community
  • Comprehensive documentation and sample implementations

Cons

  • Learning curve for advanced customizations
  • Potential performance impact on complex drawer configurations
  • Dependency on other libraries may increase app size
  • Some features may require additional setup or configuration

Code Examples

  1. Creating a basic drawer:
drawer = DrawerBuilder()
    .withActivity(this)
    .withToolbar(toolbar)
    .addDrawerItems(
        PrimaryDrawerItem().withName("Home"),
        PrimaryDrawerItem().withName("Profile"),
        DividerDrawerItem(),
        SecondaryDrawerItem().withName("Settings")
    )
    .build()
  1. Adding a custom header:
val headerView = layoutInflater.inflate(R.layout.drawer_header, null)
drawer = DrawerBuilder()
    .withActivity(this)
    .withToolbar(toolbar)
    .withHeader(headerView)
    .addDrawerItems(
        // Drawer items
    )
    .build()
  1. Handling item clicks:
drawer = DrawerBuilder()
    .withActivity(this)
    .withToolbar(toolbar)
    .addDrawerItems(
        PrimaryDrawerItem().withName("Home").withIdentifier(1),
        PrimaryDrawerItem().withName("Profile").withIdentifier(2)
    )
    .withOnDrawerItemClickListener { view, position, drawerItem ->
        when (drawerItem.identifier) {
            1L -> // Handle Home click
            2L -> // Handle Profile click
        }
        false
    }
    .build()

Getting Started

  1. Add the dependency to your build.gradle file:
implementation 'com.mikepenz:materialdrawer:9.0.1'
  1. Initialize the drawer in your activity:
class MainActivity : AppCompatActivity() {
    private lateinit var drawer: Drawer

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        drawer = DrawerBuilder()
            .withActivity(this)
            .withToolbar(toolbar)
            .addDrawerItems(
                PrimaryDrawerItem().withName("Home"),
                PrimaryDrawerItem().withName("Profile")
            )
            .build()
    }
}

Competitor Comparisons

图片选择库,单选/多选、拍照、裁剪、压缩,自定义。包括视频选择和录制。

Pros of RxGalleryFinal

  • Focuses specifically on image and video gallery functionality
  • Utilizes RxJava for reactive programming, potentially offering better performance
  • Provides a more modern UI design out of the box

Cons of RxGalleryFinal

  • Less actively maintained, with fewer recent updates
  • More limited in scope, focusing only on gallery functionality
  • Smaller community and fewer resources available for support

Code Comparison

MaterialDrawer:

drawer = DrawerBuilder()
    .withActivity(this)
    .withToolbar(toolbar)
    .addDrawerItems(
        PrimaryDrawerItem().withName("Home"),
        SecondaryDrawerItem().withName("Settings")
    )
    .build()

RxGalleryFinal:

RxGalleryFinal.with(this)
    .image()
    .multiple()
    .maxSize(8)
    .imageLoader(ImageLoaderType.GLIDE)
    .subscribe(new RxBusResultSubscriber<ImageMultipleResultEvent>() {
        @Override
        protected void onEvent(ImageMultipleResultEvent imageMultipleResultEvent) throws Exception {
            // Handle selected images
        }
    })
    .openGallery();

Summary

MaterialDrawer is a more comprehensive solution for creating navigation drawers, while RxGalleryFinal specializes in image and video gallery functionality. MaterialDrawer has a larger community and more frequent updates, making it potentially more reliable for long-term projects. RxGalleryFinal, on the other hand, offers a modern UI and reactive programming approach, which may be beneficial for specific use cases involving media selection.

😍 A beautiful, fluid, and extensible dialogs API for Kotlin & Android.

Pros of material-dialogs

  • More comprehensive dialog options, including input dialogs, progress dialogs, and color pickers
  • Easier customization of dialog appearance and behavior
  • Better support for Material Design 2.0 principles

Cons of material-dialogs

  • Focused solely on dialogs, lacking drawer functionality
  • May require additional libraries for navigation drawer implementation
  • Potentially higher learning curve for complex dialog configurations

Code Comparison

MaterialDrawer:

DrawerBuilder()
    .withActivity(this)
    .withToolbar(toolbar)
    .addDrawerItems(
        PrimaryDrawerItem().withName("Home"),
        SecondaryDrawerItem().withName("Settings")
    )
    .build()

material-dialogs:

MaterialDialog(this).show {
    title(R.string.dialog_title)
    message(R.string.dialog_message)
    positiveButton(R.string.agree)
    negativeButton(R.string.disagree)
}

Summary

MaterialDrawer specializes in creating navigation drawers with a simple API, while material-dialogs offers a wide range of dialog options with extensive customization. MaterialDrawer is more focused on drawer functionality, whereas material-dialogs provides a comprehensive solution for various types of dialogs in Material Design. The choice between the two depends on the specific requirements of your project and whether you need drawer functionality or advanced dialog options.

Side menu with some categories to choose.

Pros of Side-Menu.Android

  • Visually appealing animations and transitions
  • Lightweight and focused on a specific side menu style
  • Easy to implement with minimal configuration

Cons of Side-Menu.Android

  • Limited customization options compared to MaterialDrawer
  • Less actively maintained and updated
  • Fewer features and menu item types available

Code Comparison

Side-Menu.Android:

ResideMenu resideMenu = new ResideMenu(this);
resideMenu.setBackground(R.drawable.menu_background);
resideMenu.attachToActivity(this);
resideMenu.addMenuItem(menuItem, ResideMenu.DIRECTION_LEFT);

MaterialDrawer:

new DrawerBuilder()
    .withActivity(this)
    .withToolbar(toolbar)
    .addDrawerItems(
        new PrimaryDrawerItem().withName("Home"),
        new SecondaryDrawerItem().withName("Settings")
    )
    .build();

MaterialDrawer offers a more flexible and feature-rich API, allowing for easy creation of complex drawer layouts with various item types. Side-Menu.Android provides a simpler API focused on its specific animation style.

While Side-Menu.Android excels in providing a unique and visually appealing menu animation, MaterialDrawer offers greater customization options and a wider range of features. MaterialDrawer is also more actively maintained and updated, making it a more robust choice for long-term projects requiring extensive drawer functionality.

swipe display drawer with flowing & bouncing effects.

Pros of FlowingDrawer

  • Unique flowing animation effect for drawer opening/closing
  • Lightweight and focused on a single, visually appealing drawer style
  • Easy to implement with minimal configuration required

Cons of FlowingDrawer

  • Limited customization options compared to MaterialDrawer
  • Fewer features and drawer types available
  • Less active development and community support

Code Comparison

MaterialDrawer:

DrawerBuilder()
    .withActivity(this)
    .withToolbar(toolbar)
    .addDrawerItems(
        PrimaryDrawerItem().withName("Home"),
        SecondaryDrawerItem().withName("Settings")
    )
    .build()

FlowingDrawer:

<com.mxn.soul.flowingdrawer_core.FlowingDrawer
    android:id="@+id/drawerlayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:edMenuBackground="#303F9F"
    app:edMenuSize="260dp">
    <!-- Drawer content -->
</com.mxn.soul.flowingdrawer_core.FlowingDrawer>

MaterialDrawer offers a more programmatic approach with extensive customization options, while FlowingDrawer focuses on a specific visual style and is primarily configured through XML. MaterialDrawer provides a wider range of drawer types and features, making it more suitable for complex navigation structures. FlowingDrawer, on the other hand, excels in creating a visually striking drawer animation with minimal setup.

DrawerLayout-like ViewGroup, where a "drawer" is hidden under the content view, which can be shifted to make the drawer visible.

Pros of SlidingRootNav

  • More flexible and customizable layout options
  • Smoother animations and transitions
  • Lighter weight and less complex implementation

Cons of SlidingRootNav

  • Less comprehensive documentation and examples
  • Fewer built-in features and menu item types
  • Smaller community and fewer third-party contributions

Code Comparison

SlidingRootNav:

SlidingRootNavBuilder(this)
    .withMenuLayout(R.layout.menu_left_drawer)
    .inject()

MaterialDrawer:

DrawerBuilder()
    .withActivity(this)
    .withToolbar(toolbar)
    .addDrawerItems(
        PrimaryDrawerItem().withName("Home"),
        SecondaryDrawerItem().withName("Settings")
    )
    .build()

SlidingRootNav offers a more minimalistic approach, allowing developers to define their menu layout separately. MaterialDrawer provides a more comprehensive API with pre-defined drawer item types and built-in customization options.

Both libraries offer efficient ways to implement navigation drawers in Android applications, but they cater to different developer preferences and project requirements. SlidingRootNav is ideal for those seeking more control over the drawer's appearance and behavior, while MaterialDrawer is better suited for rapid development with a wide range of pre-built components.

Android Floating Action Button based on Material Design specification

Pros of FloatingActionButton

  • Focused specifically on implementing floating action buttons
  • Offers more customization options for FABs, including animations and labels
  • Lighter weight and easier to integrate for projects only needing FAB functionality

Cons of FloatingActionButton

  • Limited to FAB implementation, unlike MaterialDrawer's comprehensive navigation drawer solution
  • Less actively maintained, with fewer recent updates compared to MaterialDrawer
  • Smaller community and potentially less support for issues or questions

Code Comparison

MaterialDrawer:

DrawerBuilder()
    .withActivity(this)
    .withToolbar(toolbar)
    .addDrawerItems(
        PrimaryDrawerItem().withName("Home"),
        SecondaryDrawerItem().withName("Settings")
    )
    .build()

FloatingActionButton:

FloatingActionButton fab = new FloatingActionButton.Builder(this)
    .setContentView(iconView)
    .setBackgroundDrawable(R.drawable.button_action_red)
    .build();

Both libraries offer straightforward implementation, but MaterialDrawer provides a more comprehensive solution for navigation, while FloatingActionButton focuses solely on FAB functionality. The choice between them depends on the specific needs of your project and whether you require a full navigation drawer or just a floating action button.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

MaterialDrawer

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


What's included 🚀Setup 🛠️Migration Guide 🧬WIKI / FAQ 📖Used bySample App


What's included 🚀

  • the easiest possible integration
  • uses the androidX support libraries
  • compatible down to API Level 16
  • includes an AccountSwitcher
  • quick and simple api
  • follows the NEW Google Material Design Guidelines
  • use vector (.svg) icons and icon fonts via the Android-Iconics integration
  • Google Material Design Icons, Google Material Community Design Icons, FontAwesome and more
  • comes with various themes which help to get your own themes clean
  • modify the colors on the go
  • comes with multiple default drawer items
  • based on a RecyclerView
  • RTL support
  • Gmail like MiniDrawer
  • expandable items
  • badge support
  • define custom drawer items
  • tested and stable
  • sticky footer or headers
  • absolutely NO limits
  • NavController support by @petretiandrea

If you upgrade from < 8.0.0 follow the MIGRATION GUIDE

Preview

Screenshots 🎉

Image

Setup

Latest releases 🛠

  • Kotlin && Material 3 | v9.0.2
  • Kotlin | v8.4.5 (Provided as-is only)
  • Java && AndroidX | v6.1.2 (Provided as-is only)
  • Java && AppCompat | v6.0.9 (Provided as-is only)

1. Provide the gradle dependency

The latest release is available on Maven Central.

implementation("com.mikepenz:materialdrawer:9.0.1")
//required support lib modules
implementation "androidx.appcompat:appcompat:${versions.appcompat}"
implementation "androidx.recyclerview:recyclerview:${versions.recyclerView}"
implementation "androidx.annotation:annotation:${versions.annotation}"
implementation "com.google.android.material:material:1.5.0-alpha05" // requires at least 1.5.0-x
implementation "androidx.constraintlayout:constraintlayout:${versions.constraintLayout}"

NavController Support @ Maven Central.

// Add for NavController support
implementation "com.mikepenz:materialdrawer-nav:${lastestMaterialDrawerRelease}"

Android-Iconics Support @ Maven Central .

// Add for Android-Iconics support
implementation "com.mikepenz:materialdrawer-iconics:${lastestMaterialDrawerRelease}"

2. Add the Drawer into the XML

The MaterialDrawerSliderView has to be provided as child of the DrawerLayout and will as such act as the slider

<androidx.drawerlayout.widget.DrawerLayout xmlns : android ="http://schemas.android.com/apk/res/android"
xmlns:app = "http://schemas.android.com/apk/res-auto"
android:id = "@+id/root"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    ... your content ...

    <com.mikepenz.materialdrawer.widget.MaterialDrawerSliderView
        android:id="@+id/slider"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true" />
</androidx.drawerlayout.widget.DrawerLayout>

3. Add the DrawerStyle to your theme

<style name="SampleApp.DayNight" parent="Theme.Material3.DayNight.NoActionBar">
    ...
    <item name="materialDrawerStyle">@style/Widget.MaterialDrawerStyle</item>
    <item name="materialDrawerHeaderStyle">@style/Widget.MaterialDrawerHeaderStyle</item>
    ...
</style>

Great. Your drawer is now ready to use.

Note

Using v9.x with Material 3 theming requires a Material3 theme as base for the activity.

Additional Setup

Add items and adding some functionality

//if you want to update the items at a later time it is recommended to keep it in a variable
val item1 = PrimaryDrawerItem().apply { nameRes = R.string.drawer_item_home; identifier = 1 }
val item2 = SecondaryDrawerItem().apply { nameRes = R.string.drawer_item_settings; identifier = 2 }

// get the reference to the slider and add the items
slider.itemAdapter.add(
	    item1,
	    DividerDrawerItem(),
	    item2,
	    SecondaryDrawerItem().apply { nameRes = R.string.drawer_item_settings }
)

// specify a click listener
slider.onDrawerItemClickListener = { v, drawerItem, position ->
    // do something with the clicked item :D
    false
}

Selecting an item

//set the selection to the item with the identifier 1
slider.setSelection(1)
//set the selection to the item with the identifier 2
slider.setSelection(item2)
//set the selection and also fire the `onItemClick`-listener
slider.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 using isSelectable = false:

SecondaryDrawerItem().apply { nameRes = R.string.drawer_item_dialog; isSelectable = false }

Modify items or the drawer

//modify an item of the drawer
item1.apply {
  nameText = "A new name for this drawerItem"; badge = StringHolder("19")
  badgeStyle = BadgeStyle().apply { textColor = ColorHolder.fromColor(Color.WHITE); color = ColorHolder.fromColorRes(R.color.md_red_700) }
}
//notify the drawer about the updated element. it will take care about everything else
slider.updateItem(item1)

//to update only the name, badge, icon you can also use one of the quick methods
slider.updateName(1, "A new name")

//the result object also allows you to add new items, remove items, add footer, sticky footer, ..
slider.addItem(DividerDrawerItem())
slider.addStickyFooterItem(PrimaryDrawerItem().apply { nameTest = "StickyFooter" })

//remove items with an identifier
slider.removeItem(2)

//open / close the drawer
slider.drawerLayout?.openDrawer(slider)
slider.drawerLayout?.closeDrawer(slider)

//get the reference to the `DrawerLayout` itself
slider.drawerLayout

Add profiles and an AccountHeader

// Create the AccountHeader
headerView = AccountHeaderView(this).apply {
    attachToSliderView(slider) // attach to the slider
    addProfiles(
        ProfileDrawerItem().apply { nameText = "Mike Penz"; descriptionText = "mikepenz@gmail.com"; iconRes = R.drawable.profile; identifier = 102 }
    )
    onAccountHeaderListener = { view, profile, current ->
        // react to profile changes
        false
    }
    withSavedInstance(savedInstanceState)
}

Android-Iconics support

The MaterialDrawer provides an extension for the Android-Iconics library. This allows you to create your DrawerItems with an icon from any font.

Choose the fonts you need. Available Fonts

// Add for Android-Iconics support
implementation "com.mikepenz:materialdrawer-iconics:${lastestMaterialDrawerRelease}"

// fonts
implementation 'com.mikepenz:google-material-typeface:x.y.z@aar' //Google Material Icons
implementation 'com.mikepenz:fontawesome-typeface:x.y.z@aar'     //FontAwesome
//now you can simply use any icon of the Google Material Icons font
PrimaryDrawerItem().apply { iconicsIcon = GoogleMaterial.Icon.gmd_wb_sunny }
//Or an icon from FontAwesome
SecondaryDrawerItem().apply { iconicsIcon = FontAwesomeBrand.Icon.fab_github }

Advanced Setup

For advanced usecases. Please have a look at the provided sample activities.

Load images via url

The MaterialDrawer supports fetching images from URLs and setting them for the Profile icons. As the MaterialDrawer does not contain an ImageLoading library the 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 logic
DrawerImageLoader.init(object : AbstractDrawerImageLoader() {
    override fun set(imageView: ImageView, uri: Uri, placeholder: Drawable) {
        Picasso.get().load(uri).placeholder(placeholder).into(imageView)
    }

    override fun cancel(imageView: ImageView) {
        Picasso.get().cancelRequest(imageView)
    }
    
    /*
    override fun set(imageView: ImageView, uri: Uri, placeholder: Drawable, tag: String?) {
        super.set(imageView, uri, placeholder, tag)
    }

    override fun placeholder(ctx: Context): Drawable {
        return super.placeholder(ctx)
    }

    override fun placeholder(ctx: Context, tag: String?): Drawable {
        return super.placeholder(ctx, tag)
    }
    */
})

An implementation with GLIDE v4 (See tag v6.1.1 for glide v3 sample) can be found in the sample application

JVM Target 1.8

// Since 8.1.0 the drawer includes core ktx 1.3.0 which requires jvm 1.8
kotlinOptions {
    jvmTarget = "1.8"
}

Style the drawer 🖌️

Custom style - styles.xml

Create your custom style. If you don't need a custom theme see the next section, how you can set the colors just by overwriting the original colors.

// define a custom drawer style
<style name="Widget.MaterialDrawerStyleCustom" parent="Widget.MaterialDrawerStyle">
    <item name="materialDrawerInsetForeground">#4000</item>
    <!-- MaterialDrawer specific values -->
    <item name="materialDrawerBackground">?colorSurface</item>
    <item name="materialDrawerPrimaryText">@color/color_drawer_item_text</item>
    <item name="materialDrawerPrimaryIcon">@color/color_drawer_item_text</item>
    <item name="materialDrawerSecondaryText">@color/color_drawer_item_text</item>
    <item name="materialDrawerSecondaryIcon">@color/color_drawer_item_text</item>
    <item name="materialDrawerDividerColor">?colorOutline</item>
    <item name="materialDrawerSelectedBackgroundColor">?colorSecondaryContainer</item>
</style>

// define a custom header style
<style name="Widget.MaterialDrawerHeaderStyleCustom" parent="">
    <item name="materialDrawerCompactStyle">true</item>
    <item name="materialDrawerHeaderSelectionText">?colorOnSurface</item>
    <item name="materialDrawerHeaderSelectionSubtext">?colorOnSurface</item>
</style>

// define the custom styles for the theme
<style name="SampleApp" parent="Theme.Material3.Light.NoActionBar">
    ...
    <item name="materialDrawerStyle">@style/Widget.MaterialDrawerStyleCustom</item>
    <item name="materialDrawerHeaderStyle">@style/Widget.MaterialDrawerHeaderStyleCustom</item>
    ...
</style>

Adjust BezelImageView style

Overwrite the Style of the BezelImageView for the whole MaterialDrawer

<style name="BezelImageView">
    <item name="biv_maskDrawable">@drawable/material_drawer_rectangle_mask</item>
    <item name="biv_drawCircularShadow">false</item>
    <item name="biv_selectorOnPress">@color/material_drawer_primary</item>
    <item name="android:scaleType">centerInside</item>
</style>

Used by

(feel free to send me new projects)

Articles about the MaterialDrawer

Credits

Developed By

License

Copyright 2021 Mike Penz

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.