← Back to mikepenz/MaterialDrawer

How to Deploy & Use mikepenz/MaterialDrawer

MaterialDrawer Deployment and Usage Guide

Prerequisites

Development Environment

  • Android Studio (latest stable version recommended)
  • Android SDK with API Level 16 or higher
  • Kotlin support enabled in Android Studio
  • Gradle build system

Dependencies

  • AndroidX support libraries
  • Material Design Components (version 1.5.0-alpha05 or higher)
  • ConstraintLayout
  • RecyclerView
  • AppCompat

Installation

1. Add Gradle Dependency

Add the MaterialDrawer dependency to your build.gradle file:

implementation("com.mikepenz:materialdrawer:9.0.2")

Add required support libraries:

// Required support lib modules
implementation "androidx.appcompat:appcompat:${versions.appcompat}"
implementation "androidx.recyclerview:recyclerview:${versions.recyclView}"
implementation "androidx.annotation:annotation:${versions.annotation}"
implementation "com.google.android.material:material:1.5.0-alpha05"
implementation "androidx.constraintlayout:constraintlayout:${versions.constraintLayout}"

2. Add Optional Dependencies (if needed)

For NavController support:

implementation "com.mikepenz:materialdrawer-nav:9.0.2"

For Android-Iconics support:

implementation "com.mikepenz:materialdrawer-iconics:9.0.2"

3. Sync Project

After adding dependencies, sync your Gradle project in Android Studio.

Configuration

Theme Configuration

Add MaterialDrawer styles to your theme in styles.xml:

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

XML Layout Configuration

Add the MaterialDrawerSliderView to your layout XML as a child of DrawerLayout:

<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 here -->

    <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>

Build & Run

Development Build

  1. Open your project in Android Studio
  2. Select your build variant (debug/release)
  3. Click the "Run" button or use the shortcut Shift+F10
  4. Select your target device or emulator

Manual Build from Command Line

# Clean and build the project
./gradlew clean build

# Install debug build on connected device
./gradlew installDebug

# Run tests
./gradlew test

Production Build

# Build release APK
./gradlew assembleRelease

# Build release bundle
./gradlew bundleRelease

Deployment

Google Play Store

  1. Generate signed APK or App Bundle
  2. Upload to Google Play Console
  3. Follow Google Play's review process

Alternative Distribution

  • Internal Testing: Use Android Studio's built-in distribution
  • Beta Testing: Use Firebase App Distribution
  • Direct Download: Host APK on your server

Sample App

The project includes a sample app available on Google Play:

Usage Examples

Basic Drawer Setup

// Create drawer items
val item1 = PrimaryDrawerItem().apply { 
    nameRes = R.string.drawer_item_home 
    identifier = 1 
}
val item2 = SecondaryDrawerItem().apply { 
    nameRes = R.string.drawer_item_settings 
    identifier = 2 
}

// Add items to drawer
slider.itemAdapter.add(
    item1,
    DividerDrawerItem(),
    item2,
    SecondaryDrawerItem().apply { nameRes = R.string.drawer_item_settings }
)

// Set click listener
slider.onDrawerItemClickListener = { v, drawerItem, position ->
    // Handle item click
    false
}

Account Header Setup

// Create account header
val headerResult = AccountHeaderView(this, savedInstanceState).apply {
    addProfiles(
        ProfileDrawerItem().apply {
            name = "Mike Penz"
            email = "mikepenz@gmail.com"
            icon = "https://avatars.githubusercontent.com/u/1479749"
        }
    )
    withSelectionListEnabledForSingleProfile(false)
}

// Add header to drawer
slider.headerView = headerResult

Item Selection

// Set selection programmatically
slider.setSelection(1) // by identifier
slider.setSelection(item2) // by item
slider.setSelection(1, true) // with click event

// Make item non-selectable
SecondaryDrawerItem().apply { 
    nameRes = R.string.drawer_item_dialog 
    isSelectable = false 
}

Troubleshooting

Common Issues

1. Drawer Not Showing

Problem: Drawer doesn't appear when swiping or clicking hamburger icon Solution:

  • Ensure DrawerLayout is properly configured in XML
  • Check that MaterialDrawerSliderView has correct layout_gravity
  • Verify that ActionBarDrawerToggle is properly set up

2. Theme Issues

Problem: Drawer items don't match app theme Solution:

  • Ensure your theme extends Theme.Material3.DayNight.NoActionBar
  • Check that materialDrawerStyle and materialDrawerHeaderStyle are defined
  • Verify Material Design Components version compatibility

3. Icon Display Issues

Problem: Icons not displaying correctly Solution:

  • For Android-Iconics integration, ensure the dependency is added
  • Check icon font resources are properly included
  • Verify icon resource IDs are correct

4. Performance Issues

Problem: Drawer scrolling is laggy Solution:

  • Ensure RecyclerView is properly optimized
  • Check for complex item layouts
  • Consider using vector drawables instead of bitmaps

5. API Level Compatibility

Problem: App crashes on older Android versions Solution:

  • MaterialDrawer supports API Level 16 and above
  • Ensure all dependencies are compatible with target API levels
  • Check for any API-specific code that might cause crashes

Migration Issues

When upgrading from versions below 8.0.0, follow the Migration Guide for breaking changes and migration steps.

Additional Resources