Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Up arrow does not show after calling ActionBarDrawerToggle.setDrawerIndicatorEnabled(false)

The title says it all. When I call the mDrawerToggle.setDrawerIndicatorEnabled(false) I don't want the "hamburger" icon to be shown anymore but the backwards navigation arrow.

Unfortunately when I call this method just the title is shown without the backwards arrow nor the "hamburger" icon. After setting the drawerIndicatorEnabled to be true again it shows the "hamburger" icon again.

I set getSupportActionBar().setDisplayHomeAsUpEnabled(true) and getSupportActionBar().setDisplayShowHomeEnabled(true)

Edit: Basically the solution suggested here: Change drawer icon back to back arrow somehow doesn't give me the back arrow.

Does anyone know a solution for this issue? Thank you very much!

like image 551
Marcel_marcel1991 Avatar asked Jan 02 '15 12:01

Marcel_marcel1991


2 Answers

After hours of trials and errors I came up with a solution that allows to switch from "hamburger" to "arrow" and back. This is very weird and unnatural, don't ask me why it works in this way, but it works. Furthermore, this is the only solution that allowed me to do this, nothing else worked.

I have only one activity with fragments. When I'm switching from one fragment to another, I'm setting boolean variable in my activity displayingInnerFragment. For those fragments, where displayingInnerFragment == true, I show "arrow" in the top left corner, and for all others I show "hamburger". The following code I execute before switching to any fragment:

    ActionBar actionBar = getSupportActionBar();
    if (displayingInnerFragment) {
        actionBar.setDisplayHomeAsUpEnabled(false);
        drawerToggle.setDrawerIndicatorEnabled(false);
        actionBar.setDisplayHomeAsUpEnabled(true);
    } else {
        drawerToggle.setDrawerIndicatorEnabled(true);
    }

Note the double call to actionBar.setDisplayHomeAsUpEnabled() in one branch. This is required for drawerToggle.setDrawerIndicatorEnabled(false) to work. Otherwise it will not work properly. All other options either don't show "arrow" or hide "arrow" or "hamburger" at one moment or another.

like image 133
afrish Avatar answered Sep 28 '22 07:09

afrish


Use like this:

mDrawerToggle.setHomeAsUpIndicator(R.drawable.abc_ic_ab_back_mtrl_am_alpha);
mDrawerToggle.setDrawerIndicatorEnabled(false);
mDrawerToggle.syncState();
like image 28
Devendra Singh Tomar Avatar answered Sep 28 '22 06:09

Devendra Singh Tomar