Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android support Toolbar + ActionBarDrawerToggle not changing to arrow

Tags:

I'm struggling with the toolbar and drawer. I'm trying to make the burger switch to arrow when I'm adding a new fragment to the backstack but there is no way to do it.

Maybe I'm missing something but I could not find a way. Anyone had the same problem?

This is the declaration:

mDrawerToggle = new ActionBarDrawerToggle(             getActivityCompat(),                    /* host Activity */             mDrawerLayout,                    /* DrawerLayout object */             ((BaseActivity) getActivityCompat()).getToolbar(),             R.string.navigation_drawer_open,  /* "open drawer" description for accessibility */             R.string.navigation_drawer_close  /* "close drawer" description for accessibility */     ) 

This is the function I call when a fragment is added to the back stack

public void setToggleState(boolean isEnabled) {     if (mDrawerLayout == null)         return;      if (isEnabled) {         mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);         mDrawerToggle.onDrawerStateChanged(DrawerLayout.LOCK_MODE_UNLOCKED);     } else {         mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);         mDrawerToggle.onDrawerStateChanged(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);     }     mDrawerToggle.syncState(); } 
like image 483
Marcel Avatar asked Nov 11 '14 10:11

Marcel


People also ask

How do I get the back arrow on my Android toolbar?

Show back button using actionBar. setDisplayHomeAsUpEnabled(true) this will enable the back button. Custom the back event at onOptionsItemSelected. This will enable the back function to the button on the press.

What is ActionBarDrawerToggle?

androidx.appcompat.app.ActionBarDrawerToggle. This class provides a handy way to tie together the functionality of DrawerLayout and the framework ActionBar to implement the recommended design for navigation drawers.


1 Answers

I think all you have to do is to delete the third argument. Thus:

mDrawerToggle = new ActionBarDrawerToggle(      getActivityCompat(),              /* host Activity */      mDrawerLayout,                    /* DrawerLayout object */      // ((BaseActivity) getActivityCompat()).getToolbar(), <== delete this argument      R.string.navigation_drawer_open,  /* "open drawer" description for accessibility */      R.string.navigation_drawer_close  /* "close drawer" description for accessibility */     ); 

May it helps.

like image 156
hata Avatar answered Sep 17 '22 19:09

hata