1

I just created a template project in Android Studio and I did not change a line of code (DrawerLayout template project).

However, I found the clicked icon for showing the navigation fragment is always a left arrow, even though in the code it sets the icon to another one.

screenshot

Here's the code for constructing ActionBarDrawerToggle:

mDrawerToggle = new ActionBarDrawerToggle(
                getActivity(),                    /* host Activity */
                mDrawerLayout,                    /* DrawerLayout object */
                R.drawable.ic_drawer,             /* nav drawer image to replace 'Up' caret */
                R.string.navigation_drawer_open,  /* "open drawer" description for accessibility */
                R.string.navigation_drawer_close  /* "close drawer" description for accessibility */
        )

here's the png file for ic_drawer

icon

How do I change the DrawerLayout Icon?

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
Qing
  • 1,401
  • 2
  • 21
  • 41

2 Answers2

2

I've had the same problem, I have always seen the left arrow icon. I have solved in this way:

I noticed that android.support.v4.app.ActionBarDrawerToggle class has been deprecated, following some answers and from developer.android.com, in my NavigationDrawerFragment class I have used

mDrawerToggle = new ActionBarDrawerToggle(  getActivity(),                   
                                            mDrawerLayout,                    
                                            R.string.navigation_drawer_open,  
                                            R.string.navigation_drawer_close  
                                    ) { ... }

Now it's OK, the icon makes a transition to arrow only when the Navigation Drawer appears.

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
Anchor
  • 133
  • 1
  • 1
  • 7
  • seems like you are missing something from the constructor? where's your toolbar? so you set Icon in toolbar or what? – Qing Sep 30 '15 at 01:55
1

Adding on the solution given by Anchor. I managed to make mine work by changing this import

import android.support.v4.app.ActionBarDrawerToggle;

to

import android.support.v7.app.ActionBarDrawerToggle;

Doing so will prompt you an error in the constructor of ActionBarDrawerToggle. Remove the R.drawable.ic_drawer so that it becomes:

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

It should work now

mokko211
  • 597
  • 2
  • 9
  • 25