Joe Rakhimov
Joe Rakhimov

Reputation: 5083

Android - Navigation drawer with custom list item layout

I am using Mike Penz's Material Design Navigation Drawer library. I want to use my custom layout for list item of navigation drawer. I could not find in documentation. So my question is how to use custom layout for navigation drawer item?

Upvotes: 0

Views: 1086

Answers (2)

Awah Teh
Awah Teh

Reputation: 1367

Actually a much simpler solution to achieving custom drawer items, is to create your own CustomDrawerItem class (wherein you can specify the Layout resource of your drawer item). This has the added benefit of giving you additional control grammatically that rebuilding the source code and manipulating the raw XML will not.

Here is a simple Custom drawer item class in 8 lines of code

public class MyCustomDrawerItem extends AbstractBadgeableDrawerItem<MyCustomDrawerItem>
{
    @Override
    public int getType() { return R.id.material_drawer_badge_container; }

    @Override
    @LayoutRes
    public int getLayoutRes() { return R.layout.lyt_item_my_custom_drawer_item; }
}

As you can note from the example above, the two methods you want to override are getType() and getLayoutRes() with getLayoutRes() where you specify your own custom drawer item resource.

Upvotes: 1

Alok Nair
Alok Nair

Reputation: 4004

Instead of adding the library as dependency to your build.gradle, download the library from Github and edit material_drawer_item_secondary.xml or material_drawer_item_primary.xml inside layout folder, and add it to your project as library replacing the earlier one or the dependency in build.gradle. This way you can customise the navigation items.

Upvotes: 3

Related Questions