Mikepenz Material Drawer custom header

1.5k Views Asked by At

I am using a custom header in mikepenz material drawer. How can i get the onClick of the header. Can I use onDrawerItemClickListener to get the click event of the custom header ?

result = new DrawerBuilder()
                .withActivity(this)
                .withSelectedItem(-1)
                .withSliderBackgroundColorRes(R.color.white)
                .withToolbar(toolbar)
                .withStickyHeader(R.layout.nav_header)
                .withTranslucentStatusBar(true)
                .withDisplayBelowStatusBar(true)
                .addDrawerItems(
                       //Drawer Items
                ).withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
                    @Override
                    public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {


                })
                .build();
2

There are 2 best solutions below

0
On BEST ANSWER

If you have defined a header (so not the AccountHeader) you can get the reference to that view by calling the following after building the Drawer:

Drawer.getHeader()

It's very similar for the sticky header:

Drawer.getStickyHeader()

This will return you the view of the header, and allow you to set any listener you need.

1
On

You can check here. It is mentioned in doc that how you can handle header part and its events.