Search code examples
androidandroidxactionbardrawertoggle

androidx.legacy.app.ActionBarDrawerToggle' is deprecated


I use androidx library and i have androidx.legacy.app.ActionBarDrawerToggle' is deprecated error in the following code:

private ActionBarDrawerToggle mDrawerToggle;

mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
        // associate Navigation Drawer with ActionBar
        mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
                R.drawable.ic_drawer, //nav menu toggle icon

How do i suppose to change it? I tried to find a solution but nothing has to do with androidx. I would apriciate an easy explanation as i m new in android.


Solution

  • Change androidx.legacy.app.ActionBarDrawerToggle to androidx.appcompat.app.ActionBarDrawerToggle, i.e. legacy to appcompat.

    Also, remember to add your toolbar as your third argument.

    Documentation can be found here: https://developer.android.com/reference/androidx/appcompat/app/ActionBarDrawerToggle