Search code examples
androidandroid-5.0-lollipopandroid-actionbar-compatandroid-toolbar

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


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?


Solution

  • Have you tried to get themed up indicator using getV7DrawerToggleDelegate().getThemeUpIndicator () and set it after you disable the indicator?

    Because when the indicator is disabled ActionBarDrawerToggle tries to set the previous indicator.

    From ActionBarDrawerToggle source:

    public void setDrawerIndicatorEnabled(boolean enable) {
        if (enable != mDrawerIndicatorEnabled) {
            if (enable) {
                setActionBarUpIndicator((Drawable) mSlider,
                        mDrawerLayout.isDrawerOpen(GravityCompat.START) ?
                                mCloseDrawerContentDescRes : mOpenDrawerContentDescRes);
            } else {
                setActionBarUpIndicator(mHomeAsUpIndicator, 0);
            }
            mDrawerIndicatorEnabled = enable;
        }
    }
    

    Edit:

    As of deprecation of ActionBarActivity, you should use getDrawerToggleDelegate().getThemeUpIndicator ()