After changing Navigation Drawer icon it no longer opens

Asked

Viewed 255 times

0

I customize that icon from the side menu and put an icon of mine. Follow the image: inserir a descrição da imagem aqui

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

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

It would be possible to keep this icon and make the click of it open the menu ?

  • Did my answer answer answer your questions? Is there anything that needs a better explanation?

1 answer

1

It doesn’t do what you expect it to do.

ActionBarDrawerToggle#setHomeAsUpIndicator() to indicate which Drawable to use when Drawer Indicator is disabled. It is shown when setDrawerIndicatorEnabled() is called with false.
That’s why when you click on it Drawer is not shown, it is disabled.

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

  • If you are using the support appcompat

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

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setActionBar(toolbar);
    getActionBar().setHomeAsUpIndicator(R.drawable.icon_hamburg_min);
    getActionBar().setDisplayHomeAsUpEnabled(true);       
    

Browser other questions tagged

You are not signed in. Login or sign up in order to post.