### Create and Attach AccountHeader with Profiles
Source: https://github.com/mikepenz/materialdrawer/blob/develop/README.md
Initialize an `AccountHeaderView`, attach it to the slider, add profiles with text and icons, and set a listener for profile change events. Support for saved instances is included.
```kotlin
// 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)
}
```
--------------------------------
### Initialize Image Loader with Picasso
Source: https://github.com/mikepenz/materialdrawer/blob/develop/README.md
Initialize the DrawerImageLoader with a Picasso implementation to load images from URLs for profile icons. This should be done before the first image is loaded.
```kotlin
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)
}
*/
})
```
--------------------------------
### FastAdapter Upgrade Notes (v5.3.3 -> 5.3.4)
Source: https://github.com/mikepenz/materialdrawer/blob/develop/MIGRATION.md
Users of FastAdapter should review the upgrade notes for v1.6.0.
```markdown
* If you use the `FastAdapter` please read the upgrade notes for v1.6.0 (https://github.com/mikepenz/FastAdapter/releases/tag/v1.6.0)
```
--------------------------------
### Padding Control for Header (v4.3.7 -> v4.4.3)
Source: https://github.com/mikepenz/materialdrawer/blob/develop/MIGRATION.md
New methods `withHeaderPadding` (drawer) and `withPaddingBelowHeader` (header) allow separate control of padding and dividers.
```markdown
* added new method `withHeaderPadding` to the drawer and `withPaddingBelowHeader` to the header to control the padding separately from the `divider`which can be controlled via `withHeaderDivider`
```
--------------------------------
### FastAdapter Release Notes (v5.1.6 -> 5.1.8)
Source: https://github.com/mikepenz/materialdrawer/blob/develop/MIGRATION.md
Users of FastAdapter should consult the release notes for v1.4.0.
```markdown
* if you use the `FastAdapter` please check out the release notes of v1.4.0 (https://github.com/mikepenz/FastAdapter/releases/tag/v1.4.0)
```
--------------------------------
### Include Required Support Libraries
Source: https://github.com/mikepenz/materialdrawer/blob/develop/README.md
Add necessary support libraries for Material Drawer functionality. Replace `${versions.appcompat}` and other version placeholders with appropriate values.
```gradle
//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}"
```
--------------------------------
### Drawer Management of MiniDrawer (v4.5.9 -> v4.6.0)
Source: https://github.com/mikepenz/materialdrawer/blob/develop/MIGRATION.md
Enable the Drawer to manage the MiniDrawer via `withGenerateMiniDrawer(true)`. Remove manual MiniDrawer calls from listeners.
```markdown
* it is now possible to let the `Drawer` manage the `MiniDrawer`. Enable this via `withGenerateMiniDrawer(true)`. Afterwards remove the `MiniDrawer` calls inside the listeners, those are now done within the `Drawer`. You can get the `MiniDrawer` result object via `Drawer.getMiniDrawer();`
```
--------------------------------
### Import AccountHeader and AccountHeaderBuilder
Source: https://github.com/mikepenz/materialdrawer/blob/develop/MIGRATION.md
Update imports for AccountHeader and AccountHeaderBuilder classes.
```java
import com.mikepenz.materialdrawer.AccountHeader
import com.mikepenz.materialdrawer.AccountHeaderBuilder
```
--------------------------------
### Enable Legacy Material 1 Style
Source: https://github.com/mikepenz/materialdrawer/blob/develop/MIGRATION.md
Configures the Material Drawer to use the legacy Material 1 style and defines the color for selected legacy items.
```xml
- @color/material_drawer_selected
- true
```
--------------------------------
### Add espresso-contrib Dependency
Source: https://github.com/mikepenz/materialdrawer/blob/develop/FAQ/opening-drawer-from-espresso.md
Add the `espresso-contrib` library to your `build.gradle` file for instrumental tests. This library provides necessary Espresso actions for drawers.
```gradle
androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.2.2'
```
--------------------------------
### Expanding Functionality Moved to FastAdapter (v5.0.0 -> 5.0.5)
Source: https://github.com/mikepenz/materialdrawer/blob/develop/MIGRATION.md
The expanding functionality is now handled by FastAdapter. Toggling code is no longer needed in MaterialDrawer. See the provided diff for changes.
```markdown
* the `expanding` functionality is now handled by the `FastAdapter` so the toggling code is no longer needed. See the following diff for the change (just the `DrawerActivity`) https://github.com/mikepenz/MaterialDrawer/commit/88e9bdf8cccaac5aaf567ac6ffe682aeccba4f29
```
--------------------------------
### IDrawerImageLoader Interface Updates (v4.2.0 -> v4.3.0)
Source: https://github.com/mikepenz/materialdrawer/blob/develop/MIGRATION.md
The `IDrawerImageLoader` interface now includes a `placeholder(Context ctx, String tag)` method. An `AbstractDrawerImageLoader` is provided for simpler usage.
```java
placeholder(Context ctx, String tag)
```
```java
new AbstractDrawerImageLoader() {
```
```java
to keep the old behavior just change from `new DrawerImageLoader.IDrawerImageLoader() {` to `new AbstractDrawerImageLoader() {` for the `DrawerImageLoader.init`
```
```java
add new `tag` to the placeholder, to be able to define different placeholders for different targets
```
--------------------------------
### Rename Listener Method (v5.3.1 -> v5.3.2)
Source: https://github.com/mikepenz/materialdrawer/blob/develop/MIGRATION.md
The `withOnMiniDrawerItemClickListener` method has been renamed to `withOnMiniDrawerItemOnClickListener`. A new `OnMiniDrawerItemClickListener` is introduced.
```markdown
* the `withOnMiniDrawerItemClickListener` was renamed to `withOnMiniDrawerItemOnClickListener`
* added new separate `OnMiniDrawerItemClickListener` which allows to hook into the default behavior, and prevent it if necessary
* NOTE: this one now uses the `withOnMiniDrawerItemClickListener` method.
```
--------------------------------
### Apply Drawer Styles to Theme
Source: https://github.com/mikepenz/materialdrawer/blob/develop/README.md
Add the `materialDrawerStyle` and `materialDrawerHeaderStyle` items to your application's theme to customize the drawer's appearance.
```xml
```
--------------------------------
### Create Drawer Without Default Selection
Source: https://github.com/mikepenz/materialdrawer/blob/develop/FAQ.md
To create a drawer without a default selection, set the selection to -1.
```kotlin
//just set the selection to -1
slider.setSelectionAtPosition(-1)
```
--------------------------------
### Add, Remove, and Manage Drawer Items
Source: https://github.com/mikepenz/materialdrawer/blob/develop/README.md
Add new items, including dividers and sticky footer items, or remove items by their identifier. The result object provides methods for these manipulations.
```kotlin
//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 Drawer with Espresso
Source: https://github.com/mikepenz/materialdrawer/blob/develop/FAQ/opening-drawer-from-espresso.md
Use `onView` with the drawer layout ID and `DrawerActions.open()` to programmatically open the drawer during an Espresso test. The default drawer layout ID is `R.id.material_drawer_layout`.
```java
onView(withId(R.id.material_drawer_layout)).perform(DrawerActions.open());
```
--------------------------------
### Add ImageView Placeholder Method (v5.5.1)
Source: https://github.com/mikepenz/materialdrawer/blob/develop/MIGRATION.md
A new method `void set(ImageView imageView, Uri uri, Drawable placeholder, String tag)` is added to the `IDrawerImageLoader` interface.
```java
void set(ImageView imageView, Uri uri, Drawable placeholder, String tag);
```
--------------------------------
### Set JVM Target to 1.8
Source: https://github.com/mikepenz/materialdrawer/blob/develop/README.md
Configure the JVM target to 1.8 for the Kotlin compiler. This is required since version 8.1.0 of the drawer which includes core ktx 1.3.0.
```kotlin
kotlinOptions {
jvmTarget = "1.8"
}
```
--------------------------------
### Add NavController Support Dependency
Source: https://github.com/mikepenz/materialdrawer/blob/develop/README.md
Include this dependency if you are using NavController support with Material Drawer. Replace `${lastestMaterialDrawerRelease}` with the correct version.
```gradle
// Add for NavController support
implementation "com.mikepenz:materialdrawer-nav:${lastestMaterialDrawerRelease}"
```
--------------------------------
### Apply Custom Drawer and Header Styles in Theme
Source: https://github.com/mikepenz/materialdrawer/blob/develop/README.md
Apply the custom drawer and header styles to your application's theme. This ensures that the MaterialDrawer uses your defined styles throughout the application.
```xml
```
--------------------------------
### Control Drawer Layout Open/Close and Access DrawerLayout
Source: https://github.com/mikepenz/materialdrawer/blob/develop/README.md
Open or close the Material Drawer programmatically using the `openDrawer` and `closeDrawer` methods. The underlying `DrawerLayout` can also be accessed.
```kotlin
//open / close the drawer
slider.drawerLayout?.openDrawer(slider)
slider.drawerLayout?.closeDrawer(slider)
//get the reference to the `DrawerLayout` itself
slider.drawerLayout
```
--------------------------------
### Select Drawer Item by Identifier or Object
Source: https://github.com/mikepenz/materialdrawer/blob/develop/README.md
Set the selected item in the drawer using its identifier or the item object itself. Optionally, trigger the click listener when setting the selection.
```kotlin
//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)
```
--------------------------------
### Support Libraries Dependency Update (v4.3.7)
Source: https://github.com/mikepenz/materialdrawer/blob/develop/MIGRATION.md
MaterialDrawer v4.3.7 depends on support libraries v23.1.0, requiring `compileSDKVersion 23`.
```markdown
* depends on the latest `v23.1.0` **support libraries**. Those also require you to have `compileSDKVersion 23`
```
--------------------------------
### Add Material Drawer Gradle Dependency
Source: https://github.com/mikepenz/materialdrawer/blob/develop/README.md
Include the latest release of the Material Drawer library as a Gradle dependency. Ensure you replace `${latestRelease}` with the actual latest version.
```gradle
implementation("com.mikepenz:materialdrawer:${latestRelease}")
```
--------------------------------
### Identifier Type Change and Status Bar Handling (v4.6.0 -> v5.0.0)
Source: https://github.com/mikepenz/materialdrawer/blob/develop/MIGRATION.md
Identifier type changed from `int` to `long`. `FULL_SCREEN` flag removed; `fitsSystemWindows` is now used for drawer display below the status bar. `Drawer.getDrawerLayout().setStatusBarBackgroundColor(color)` is the new way to set status bar color.
```markdown
* the identifier was changed from `int` to `long` as the internal adapter (FastAdapter) uses `long` to identify items (as the `Adapter` does)
* v5.0.0 no longer sets the `FULL_SCREEN` flag to get the drawer below the `StatusBar` it now uses the `fitsSystemWindows` everywhere. This should improve compatiblity with a lot of things like the `CoordinatorLayout` and should also improve compatiblity with future Android updates
* removed the following methods:
* DrawerUIUtils.getScreenWidth -> moved to UIUtils from the `Materialize` library
* DrawerBuilder.withTranslucentStatusBarProgrammatically -> no longer necessary as we now depend on the `fitsSystemWindows` flag
* `StatusBarColor` can now be set via the `Drawer.getDrawerLayout().setStatusBarBackgroundColor(color)`
* DrawerBuilder.keyboardSupportEnabled -> `KeyboardUtil` should no longer be necessary
* `StatusBar` on **API < 21** is no longer colored, because of the changed way how we display the `Drawer` under the `StatusBar`
* `DrawerItems` changed. Please take a look at the `CustomDrawerItems` from the sample or the default ones, to add the changes to your `CustomDrawerItems`
* ...
```
--------------------------------
### Update FastAdapter Dependency (v5.7.0)
Source: https://github.com/mikepenz/materialdrawer/blob/develop/MIGRATION.md
Users of FastAdapter need to update to v2.0.0 with MaterialDrawer v5.7.0. Custom drawer items may require implementing new methods.
```markdown
* You have to update your `FastAdapter` dependency to v2.0.0 with this release
* If you have `CustomDrawerItem`'s not based on the `AbstractDrawerITems` make sure you implement the `unbindView` method, and the new required methods
* See the MIGRATION information of the **FastAdapter** https://github.com/mikepenz/FastAdapter/blob/develop/MIGRATION.md
```
--------------------------------
### Force Specific Sub-Dependency Versions with Gradle
Source: https://github.com/mikepenz/materialdrawer/blob/develop/FAQ/howto_use_different_sub_library_version.md
Use this Gradle configuration in your module's build.gradle file to force specific versions for Android support libraries. This is useful for managing version conflicts or ensuring compatibility.
```gradle
configurations.all {
resolutionStrategy.force "com.android.support:support-v4:${versions.androidX}"
resolutionStrategy.force "com.android.support:appcompat-v7:${versions.androidX}"
resolutionStrategy.force "com.android.support:cardview-v7:${versions.androidX}"
resolutionStrategy.force "com.android.support:recyclerview-v7:${versions.androidX}"
resolutionStrategy.force "com.android.support:design:${versions.androidX}"
resolutionStrategy.force "com.android.support:support-annotations:${versions.androidX}"
}
```
--------------------------------
### Update FastAdapter Dependency (v5.8.0)
Source: https://github.com/mikepenz/materialdrawer/blob/develop/MIGRATION.md
Users of FastAdapter need to update to v2.1.0 with MaterialDrawer v5.8.0.
```markdown
* You have to update your FastAdapter dependency to v2.1.0 with this release
* See the MIGRATION information of the FastAdapter https://github.com/mikepenz/FastAdapter/blob/develop/MIGRATION.md
```
--------------------------------
### Add Android-Iconics Support Dependency
Source: https://github.com/mikepenz/materialdrawer/blob/develop/README.md
Include this dependency to integrate Android-Iconics with Material Drawer. Replace `${lastestMaterialDrawerRelease}` with the correct version.
```gradle
// Add for Android-Iconics support
implementation "com.mikepenz:materialdrawer-iconics:${lastestMaterialDrawerRelease}"
```
--------------------------------
### Add Items and Functionality to Drawer
Source: https://github.com/mikepenz/materialdrawer/blob/develop/README.md
Add primary and secondary drawer items, including dividers, to the slider. A click listener can be specified for handling item interactions.
```kotlin
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
}
```
--------------------------------
### Define Custom Drawer Style
Source: https://github.com/mikepenz/materialdrawer/blob/develop/README.md
Define a custom style for the MaterialDrawer by extending the default Widget.MaterialDrawerStyle. This allows customization of various elements like background, text colors, icon colors, and selected background.
```xml
```
--------------------------------
### Define Header Selection Subtext Color
Source: https://github.com/mikepenz/materialdrawer/blob/develop/MIGRATION.md
Defines the color for the subtext item in the Material Drawer header.
```xml
- @color/material_drawer_header_selection_subtext
```
--------------------------------
### Define Custom Header Style
Source: https://github.com/mikepenz/materialdrawer/blob/develop/README.md
Define a custom style for the MaterialDrawer header. This allows setting properties like compact style and text colors for header selection and subtext.
```xml
```
--------------------------------
### Keep WebView JavaScript Interface Class
Source: https://github.com/mikepenz/materialdrawer/blob/develop/materialdrawer/proguard-rules.txt
Uncomment and specify the fully qualified class name if your project uses WebView with JavaScript interfaces to prevent them from being removed by ProGuard.
```proguard
-keepclassmembers class fqcn.of.javascript.interface.for.webview {
public *;
}
```
--------------------------------
### Disable Dropdown for Single Profile
Source: https://github.com/mikepenz/materialdrawer/blob/develop/FAQ/accountheader_single_profile_without_dropdown.md
Set `selectionListEnabledForSingleProfile` to `false` on the AccountHeader Builder to disable the dropdown and hide the arrow when only one profile is present.
```kotlin
headerView.selectionListEnabledForSingleProfile = false
```
--------------------------------
### Add Android-Iconics Support Dependency
Source: https://github.com/mikepenz/materialdrawer/blob/develop/README.md
Include the necessary Gradle dependency for Android-Iconics support in your project to use font icons within Material Drawer items.
```gradle
// 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
```
--------------------------------
### Dropping Support for API < 14 (v5.5.0)
Source: https://github.com/mikepenz/materialdrawer/blob/develop/MIGRATION.md
MaterialDrawer v5.5.0 drops support for Android API levels below 14. The new minimum SDK version is 14.
```markdown
* **Dropping support for API < 14. New MinSdkVersion is 14**
```
--------------------------------
### Modify Drawer Item Properties and Update Drawer
Source: https://github.com/mikepenz/materialdrawer/blob/develop/README.md
Update properties like name and badge for an existing drawer item and notify the slider to refresh. Quick methods are available for updating specific properties like name.
```kotlin
//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")
```
--------------------------------
### SecondaryDrawerItem Subclass Change (v5.2.0 -> v5.2.1)
Source: https://github.com/mikepenz/materialdrawer/blob/develop/MIGRATION.md
The `SecondaryDrawerItem` is now a subclass of `PrimaryDrawerItem`. Ensure `instanceOf` checks for `SecondaryDrawerItem` are performed first.
```markdown
* the `SecondaryDrawerItem` is now a subclass of the `PrimaryDrawerItem` (extends `PrimaryDrawerItem`). If you have an `if` which checks for the type with `instanceOf` make sure you check for the `SecondaryDrawerItem` first. (`secondaryDrawerItem instanceOf PrimaryDrawerItem == true`)
```
--------------------------------
### Add MaterialDrawerSliderView to XML Layout
Source: https://github.com/mikepenz/materialdrawer/blob/develop/README.md
Define the `MaterialDrawerSliderView` within your `DrawerLayout` in the XML layout file. This view acts as the drawer's content.
```xml
... your content ...
```
--------------------------------
### Include FontAwesome Typeface
Source: https://github.com/mikepenz/materialdrawer/blob/develop/MIGRATION.md
Add the FontAwesome typeface dependency for use with Android-Iconics. Note that the package name has changed.
```gradle
compile 'com.mikepenz:fontawesome-typeface:4.4.0.1@aar' //FontAwesome **NOTE:** the packagename changed for this font
```
--------------------------------
### Custom Drawer Item Interface Change (v5.6.0)
Source: https://github.com/mikepenz/materialdrawer/blob/develop/MIGRATION.md
MaterialDrawer v5.6.0 introduces a breaking interface change for custom drawer items. Implement `bindView(ViewHolder holder, List payloads)` instead of `bindView(VH holder)`.
```markdown
* This release brings a breaking interface change. Your items now have to implement `bindView(ViewHolder holder, List payloads)` instead of `bindView(VH holder)`.
* The additional payload can be used to implement a more performant view updating when only parts of the item have changed. Please also refer to the `DiffUtils` which may provide the payload.
```
--------------------------------
### Include Google Material Design Icons Font
Source: https://github.com/mikepenz/materialdrawer/blob/develop/MIGRATION.md
Add the Google Material Design Icons font dependency for use with Android-Iconics.
```gradle
compile 'com.mikepenz:google-material-typeface:1.2.0.1@aar' //Google Material Design Icons
```
--------------------------------
### Make Drawer Item Non-Selectable
Source: https://github.com/mikepenz/materialdrawer/blob/develop/README.md
Disable the default selection behavior for a specific drawer item by setting its `isSelectable` property to `false`.
```kotlin
SecondaryDrawerItem().apply { nameRes = R.string.drawer_item_dialog; isSelectable = false }
```
--------------------------------
### Use Android-Iconics Font Icons in Drawer Items
Source: https://github.com/mikepenz/materialdrawer/blob/develop/README.md
Assign icons from Google Material Icons or FontAwesome to `PrimaryDrawerItem` or `SecondaryDrawerItem` using the `iconicsIcon` property.
```kotlin
//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 }
```
--------------------------------
### Adjust BezelImageView Style
Source: https://github.com/mikepenz/materialdrawer/blob/develop/README.md
Overwrite the default style for BezelImageView used within the MaterialDrawer. This allows customization of mask drawable, shadow, and press effect.
```xml
```
--------------------------------
### Lock DrawerLayout in MaterialDrawer
Source: https://github.com/mikepenz/materialdrawer/blob/develop/FAQ.md
You can lock the MaterialDrawer by using the DrawerLayout's setDrawerLockMode method. This allows control over whether the drawer can be opened with gestures or the navigation icon.
```java
drawerLayout.setDrawerLockMode(int lockMode); //or (int lockMode, int edgeGravity)
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.