After changing the Navigation Drawer icon it does not open anymore

1

I customized that side menu icon and put an icon of mine. Here is the image:

Problem: When I click on the Icon, it no longer opens that menu on the side. Here is the code I used to change the icon:

toggle.setHomeAsUpIndicator(R.drawable.icon_hamburg_min);
drawer.setDrawerListener(toggle);

Would it be possible to keep this icon and make its click open the menu?

    
asked by anonymous 19.06.2017 / 17:05

1 answer

0

This does not do what you expect it to do.

ActionBarDrawerToggle # setHomeAsUpIndicator () serves to indicate which drawable to use when the drawer indicator is disabled. It is shown when setDrawerIndicatorEnabled () is called with false . This is why when you click on it drawer is not shown, it is disabled.

To change the icon you should use ActionBar # setHomeAsUpIndicator () , do so:

  • If you are using support appcompat

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setHomeAsUpIndicator(R.drawable.icon_hamburg_min);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);       
    
  • If it is not

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setActionBar(toolbar);
    getActionBar().setHomeAsUpIndicator(R.drawable.icon_hamburg_min);
    getActionBar().setDisplayHomeAsUpEnabled(true);       
    
19.06.2017 / 18:56