ActionBarDrawerToggle cannot be applied to Android.support.v7.widget.Toolbar

I keep getting an error saying that ActionBarDrawerToggle cannot be applied to v7.widget.Toolbar, and because I watched others fix a similar problem, they now support the support library files, but for some reason the error does not disappear.

The error says that the ActionBarDrawerToggle() in the ActionBarDrawerToggle cannot be applied to android.support.v7.widget.Toolbar , and then with the actual argument R.id.drawable_ic_drawer (int)

 import android.support.v7.app.ActionBarDrawerToggle; import android.support.v4.view.GravityCompat; import android.support.v4.widget.DrawerLayout; import android.content.SharedPreferences; import android.content.res.Configuration; import android.os.Bundle; import android.preference.PreferenceManager; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.Toast; import android.support.v7.widget.Toolbar; 

  mDrawerToggle = new android.support.v7.app.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 */ ) { 

The part that is said to make a mistake is R.drawer.ic_drawer. How to resolve it?

+7
android navigation-drawer android-toolbar
source share
2 answers

The ActionBarDrawerToggle constructor is as follows.

 android.support.v7.app.ActionBarDrawerToggle.ActionBarDrawerToggle(Activity activity, DrawerLayout drawerLayout, Toolbar toolbar, int openDrawerContentDescRes, int closeDrawerContentDescRes) 

You pass R.drawable.ic_drawer drawable instead of the toolbar, why you get this error.

Create a toolbar and add it as an action panel and pass this toolbar to this constructor.

+9
source share

An alternative way to solve this problem is to import import android.support.v4.widget.DrawerLayout instead of import android.support.v7.widget.DrawerLayout

According to google documentation here: http://developer.android.com/reference/android/support/v4/app/ActionBarDrawerToggle.html

+3
source share

All Articles