2

My application uses ActionBarCompat library as well as the NavigationDrawer support library. I use ActionBarDrawerToggle appcompat v7 to get the drawer. There are a custom search view on ActionBar. Like this:

enter image description here

But the drawer indicator shows wrongly, doesn't show the Back Arrow when action search view is expanded; enter image description here

I want it to show like PlayStore application:

enter image description here

How can I do it? Thanks in advance.

Huy Duong Tu
  • 7,798
  • 5
  • 25
  • 46

4 Answers4

3

There is simple and quick solution to this.

First, you should know now the android.support.v4.app.ActionBarDrawerToggle is deprecated. You must replace that with android.support.v7.app.ActionBarDrawerToggle.

Here is an Example showing the same.

DrawerLayout mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle mDrawerToggle = new ActionBarDrawerToggle(
        this,  mDrawerLayout, mToolbar,
        R.string.navigation_drawer_open, R.string.navigation_drawer_close
    );
    mDrawerLayout.setDrawerListener(mDrawerToggle);

After that use support Action Bar as shown here in this documentation and then your drawer indicator will show correctly also showing the Back Arrow when action search view is expanded.

Remember to use com.android.support:appcompat-v7:21.0.+" (Api level 21) and android.support.v7.app.ActionBar

You can set up the support library using this guide.

AND after that your drawer indicator will perfectly look like this..!!!

AND then your drawer indicator will perfectly look like this.

Abhi1227
  • 416
  • 4
  • 7
1

You got that issue because you set (android:)homeAsUpIndicator in your theme. Remove that attribute will solve your problem.

Wayne
  • 6,361
  • 10
  • 46
  • 69
0

This is not the arrow from ActionBarDrawerToggle. I think Google uses Toolbar as they do in google io app. On OnClick event they just change toolbar navigation icon with toolbar.setNavigationIcon(R.id.ic_up). And R.id.ic_up - is a custom arrow drawable.

bluebyte
  • 560
  • 2
  • 7
  • 23
0

For me none of solutions posted here in SO worked. I had to look under the hood of support library to find out why and when is the home icon set and I noticed few things. The main observation is that the icon is set in this function:

android.support.v7.widget.Toolbar#setNavigationIcon(android.graphics.drawable.Drawable)

on the line

 mNavButtonView.setImageDrawable(icon);

If you are facing the same problem as I was and none of suggested solutions work (setting theme, trying to call setNavigationIcon on toolbar, setHomeAsUpIndicator on Actionbar or even something else), I suggest to locate function mentioned above and put breakpoint there. You can then see when the function is called and identify the last function call (from the Frame window in android studio) that sets up the icon. For me it was this activity life-cycle method syncing navigation drawer:

@Override
protected void onPostCreate(Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);
    mDrawerToggle.syncState();
    mToolbar.setNavigationIcon(R.drawable.ic_hamburger);
}

I simply added last line and it worked.

vanomart
  • 1,739
  • 1
  • 18
  • 39