Home » Android » android – Deprecated ActionBarDrawerToggle

android – Deprecated ActionBarDrawerToggle

Posted by: admin June 15, 2020 Leave a comment


I was trying to implement the android.support.v4.app.ActionBarDrawerToggle in my app; since this class is deprecated

This class is deprecated. Please use ActionBarDrawerToggle in

I’ve switched to android.support.v7.app.ActionBarDrawerToggle.

Before I could call the constructor in this way:

mDrawerToggle = new ActionBarDrawerToggle(
    this,                  /* host Activity */
    mDrawerLayout,         /* DrawerLayout object */
    R.drawable.ic_drawer,  /* nav drawer image to replace 'Up' caret */
    R.string.drawer_open,  /* "open drawer" description for accessibility */
    R.string.drawer_close  /* "close drawer" description for accessibility */
    public void onDrawerClosed(View view) {
        invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()

    public void onDrawerOpened(View drawerView) {
        invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()

but after I’ve switched to the newer v7 support library, I receive the error

"ActionBarDrawerToggle() in ActionBarDrawerToggle cannot be applied to:
toolbar: android.support.v7.widget.Toolbar 
Actual arguments: R.drawable.ic_drawer (int)"

Apparently I am not introducing a proper Toolbar into the constructor, but I’m not sure to understand the difference between the two conflicting arguments. How do I get the required toolbar?

How to&Answers:

I solved my problem by importing the newer android.support.v7.app.ActionBarDrawerToggle and by using the RecyclerView instead of the ListView as shown in this example: How to make Material Design Navigation Drawer With Header View:

private ActionBarDrawerToggle mDrawerToggle;
//... ... 
mDrawerToggle = new ActionBarDrawerToggle(
            R.string.drawer_open, R.string.drawer_close){
                    public void onDrawerOpened(View drawerView) {
                        // code here will execute once the drawer is opened 
                        invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
                    public void onDrawerClosed(View drawerView) {
                        // Code here will execute once drawer is closed

If you still have trouble check here:
How to replace deprecated android.support.v4.app.ActionBarDrawerToggle