Search code examples
androidandroid-actionbar

How to set a custom back button in ActionBar?


I am creating an ActionBar (SupportActionBar, more precisely) this way:

android.support.v7.app.ActionBar actionBar=getSupportActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
    actionBar.setDisplayShowTitleEnabled(true);
    actionBar.setHomeButtonEnabled(true);
    actionBar.setDisplayHomeAsUpEnabled(true);
    //actionBar.setDisplayOptions(actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE););
    actionBar.setIcon(R.drawable.ic_drawer);
    actionBar.setTitle(mTitle);

This way, I get a button in my action bar which, once clicked, does what I want it to do. But, it displays an arrow pointing to the left. I would like to display another drawable, so I uncomment the setDisplayOptions line, and the icon I want is displayed. But, the button is no longer clickable.

How could I set my drawable to the button, and maintaining it clickable?


Solution

  • Use setHomeAsUpIndicator() method instead

    actionBar.setHomeAsUpIndicator(R.drawable.ic_drawer);