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(); }
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With