Reputation: 1028
I recently updated my app to use navigation drawer in 2 activities (instead of only one, as it used to be). For this, made an DrawerActivity parent class, and I extend this class on the two activities I want to use it on. The problem is, instead of showing the three lines symbol, it shows the back arrow symbol. Previously, when I used only in the main activity the navigation drawer, it was shown as it should (with the three lines), like this:
Here's the code that I use for this:
drawerListener = new ActionBarDrawerToggle(this, drawerLayout,
R.drawable.ic_navigation_drawer, R.string.navigation_drawer_open,
R.string.navigation_drawer_close) {
@Override
public void onDrawerClosed(View drawerView) {
super.onDrawerClosed(drawerView);
}
@Override
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
}
@Override
public void onDrawerSlide(View drawerView, float slideOffset) {
}
}
getActionBar().setHomeButtonEnabled(true);
getActionBar().setDisplayHomeAsUpEnabled(true);
Any ideas why it shows the back button, instead of the three lines ? Thank you.
Upvotes: 0
Views: 7040
Reputation: 15
Just Add this,
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
new ActionBarDrawerToggle(this, (DrawerLayout) findViewById(R.id.drawer_layout),
(Toolbar) findViewById(R.id.toolbar), R.string.navigation_drawer_open,
R.string.navigation_drawer_close) {}.syncState();
}
Upvotes: 1
Reputation: 11711
In my case, removing the line actionBarDrawerToggle.setDrawerIndicatorEnabled(false);
worked and replaced the back arrow with three lines again.
setDrawerIndicatorEnabled is true by default. By mistake, I had made it false.
Upvotes: 0
Reputation: 1028
OK, after long „battles” with it, I finally realized what was the problem. It seems that it has nothing to do with the code posted in the question, the activity was missing the onPostCreate() method with the syncState() function:
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
drawerListener.syncState();
}
Thank you all for the support and hope this will help others avoid forgetting the syncState() function.
Upvotes: 3
Reputation: 15165
Try to change your code to this:
// enabling action bar app icon and behaving it as toggle button.
// call these codes before calling "setDrawerListener(drawerListener)"
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
// set up the drawerListener
drawerListener = new ActionBarDrawerToggle(this, mDrawerLayout,
R.drawable.ic_drawer, //nav menu toggle icon
R.string.app_name, // nav drawer open - description for accessibility
R.string.app_name // nav drawer close - description for accessibility
) {
public void onDrawerClosed(View view) {
// calling onPrepareOptionsMenu() to show action bar icons
invalidateOptionsMenu();
}
public void onDrawerOpened(View drawerView) {
// calling onPrepareOptionsMenu() to hide action bar icons
invalidateOptionsMenu();
}
};
mDrawerLayout.setDrawerListener(drawerListener);
Where R.drawable.ic_drawer
is a icon in drawable
resource folder which shows the three lines icon. Download ic_drawer
here and import it into your project.
Upvotes: 0