Materialdrawer: Using MaterialDrawer with Kotlin

Created on 21 Jan 2021  路  6Comments  路  Source: mikepenz/MaterialDrawer

first thanks for this beautiful plugin.i just was following along about how to add a toolbar since i couldn't find out alot with samples and i found the wiki faq page but unfortunately links are broken.

question

All 6 comments

@lumos675 the best way to get started beside the README will be to install the sample app and find a usecase close to what you want to achieve :)

After that you can use the sample apps code: https://github.com/mikepenz/MaterialDrawer/tree/develop/app and get a better understanding how you can implement it.


The library itself provides the contents for a DrawerLayout so it does not handle the Toolbar nor the DrawerLayout for your.

Sorry i am noob Mike.The documention for kotlin part didn't help me at all. i could make it work but i can not add new items to menus. in samples which i opened all of them are using data binding..is there anyway to use it without data binding?is there any start point and examples of how to use it in kotlin?in your samples i can see that slider and drawerlayout definded which i can see you used data binding

The sample application makes use of ViewBinding which just replaces the findViewById statements.

You can simply use it without ViewBinding but it's suggested to use it (see the official google docs for it)

The sample app code is in kotlin so it will highlight all the different ways to use the library.


The DrawerActivity for example shows a complete sample, with header, items, and click listener...
https://github.com/mikepenz/MaterialDrawer/blob/develop/app/src/main/java/com/mikepenz/materialdrawer/app/DrawerActivity.kt

But there are a lot more sample activities in the sample app


Beside that you can follow the 3 initial steps to setup the drawer from the README and after that see the section to add items:
https://github.com/mikepenz/MaterialDrawer#add-items-and-adding-some-functionality

Thank you so much your answer helped me alot

for those people which want to start using the newest version of MaterialDrawyer i suggest you to read this article first
https://developer.android.com/topic/libraries/view-binding#kotlin
then after having better understanding about view binding and data binding you can make the newest version work in no time add items and do tweaks.
it took me less than 20 minutes to learn how to work with it after had better understanding about viewbinding.
so i just simply added this to my build.grade on my app

android {
    ...
    buildFeatures {
        viewBinding true
    }
}

then i just could simply use any sample made by Mike Penz.

@lumos675 please remember ViewBinding is not required

You can also do the old way. like findViewById<MaterialDrawerSliderView>(R.id.slider) but ViewBinding is just more superior :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Meeks91 picture Meeks91  路  3Comments

sonh picture sonh  路  3Comments

jd-alexander picture jd-alexander  路  4Comments

ghost picture ghost  路  3Comments

Ahmed-Emad picture Ahmed-Emad  路  4Comments