Missing Up navigation icon after switching from ICS ActionBar to Lollipop Toolbar

Andrey Novikov picture Andrey Novikov · Oct 24, 2014 · Viewed 9k times · Source

I have an activity with many fragments that uses action bar and navigation drawer. It has "home as up" enabled. I have implemented proper logic that only top level fragments show action bar drawer toggle icon, other fragments show up arrow. I achieved this by:

mDrawerToggle.setDrawerIndicatorEnabled(false);
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, mDrawerList);

Now old v4 support library ActionBarDrawerToggle became deprecated. I've switched to v7 version together with new Toolbar to get Material Design look. After that when drawer is open "up" arrow is correctly displayed, but when the above-mentioned code is executed it disappears completely.

Is it a bug in support library or I have to do something different to show "up" arrow instead of drawer indicator?

Answer

gmsalex picture gmsalex · Nov 14, 2014

Answer/comments of Nikola Despotoski and Andrey Novikov are perfectly correct but I want to mention that after toolbar was replaced with following code:

drawerToggle.setDrawerIndicatorEnabled(false);
drawerToggle.setHomeAsUpIndicator(getV7DrawerToggleDelegate().getThemeUpIndicator());
setSupportActionBar(toolbar);

your activity will receive every onOptionsItemsSelected events even if you enable your drawer toogle again drawerToggle.setDrawerIndicatorEnabled(true); So you need to handle this, I've ended with

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
            if (drawerToggle.isDrawerIndicatorEnabled()) {
                return drawerToggle.onOptionsItemSelected(item);
            } else {
                onBackPressed();
                return true;
            }
        default:
            return super.onOptionsItemSelected(item);
    }
}