Deprecated ActionBarDrawerToggle

I tried to implement android.support.v4.app.ActionBarDrawerToggle in my application; since this class is deprecated

This class is deprecated. Please use ActionBarDrawerToggle in Support-v7-AppCompat.

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

Before I could call the constructor as follows:

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) { getActionBar().setTitle(mTitle); invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() } public void onDrawerOpened(View drawerView) { getActionBar().setTitle(mDrawerTitle); invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() } }; 

but after switching to a newer v7 support library I get an error

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

Apparently, I do not represent the correct toolbar in the constructor, but I'm not sure I understand the difference between the two conflicting arguments. How to get the necessary toolbar?

+8
android navigation-drawer
source share
2 answers

I solved my problem by importing a new android.support.v7.app.ActionBarDrawerToggle and using RecyclerView instead of ListView, as shown in this example: How to create a material structure Navigation box with a header image :

 private ActionBarDrawerToggle mDrawerToggle; //... ... mDrawerToggle = new ActionBarDrawerToggle( this, mDrawerLayout, toolbar, R.string.drawer_open, R.string.drawer_close){ @Override public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); // code here will execute once the drawer is opened getSupportActionBar().setTitle(mTitle); invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() } @Override public void onDrawerClosed(View drawerView) { super.onDrawerClosed(drawerView); // Code here will execute once drawer is closed getSupportActionBar().setTitle(mDrawerTitle); invalidateOptionsMenu(); }; 

If you still have a problem, check here: How to replace the deprecated android.support.v4.app.ActionBarDrawerToggle file

+19
source share

go to Gradle properties and add this

 android.useAndroidX=true android.enableJetifier=true 

after that go and import it into your java file

 import androidx.appcompat.app.ActionBarDrawerToggle; 
0
source share

All Articles