Search code examples
androidtoolbaraction-button

Change toolbar button behaviour in android


I implemented a Side Drawer that opens from right to left. Now I want to replace the default menu icon (3 dots) with another icon.

If the "new icon" is clicked, the side drawer should be opened.

I cant get this to work, and need a bit of help. Thanks in advance.


Solution

  • simply add an item in your menu with showAsAction="always" and set icon of your desire and add following code in onOptionsItemSelected

    @Override
        public boolean onOptionsItemSelected(MenuItem item) {
    
        if(item.getItemId()==R.id.your item id){
        drawer.open();
        }
    }