androidmaterialdrawer

Mikepenz Material Drawer custom header


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();

Solution

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