Reputation:
After reading the following question, I still can't figure out how to replace my Navigation Drawer
's menu with a simple back arrow that lets my user go back to the previous Fragment
.
So far I'm able to hide the button to access the Drawer
like such:
public void setDrawerState(boolean isEnabled) {
if ( isEnabled ) {
drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
toggle.setDrawerIndicatorEnabled(true);
toggle.syncState();
}
else {
drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
toggle.setDrawerIndicatorEnabled(false);
toggle.syncState();
}
}
How may I add the back arrow at its place?
Upvotes: 0
Views: 1103
Reputation: 211
It's little late but I found one workaround. I have used following in my activity
Firstly set drawer locked mode
fullLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
Then add below code to display back button
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
Then create drawer toggle and add drawer listner. Use below code.
ActionBarDrawerToggle mToggle = new ActionBarDrawerToggle(this, fullLayout, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
mToggle.setDrawerIndicatorEnabled(false);
mToggle.syncState();
mToggle.setToolbarNavigationClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//Backpress action
finish();
}
});
fullLayout.setDrawerListener(mToggle);
Note - method setDrawerListener
is deprecated. Modify above code as per your need.
Upvotes: 1