I keep getting the error saying ActionBarDrawerToggle cannot be applied to v7.widget.Toolbar and because I looked at how others fixed a similar issue they are now both support library files but the error doesn't go away for some reason.
The error says ActionBarDrawerToggle()
in ActionBarDrawerToggle
cannot be applied to android.support.v7.widget.Toolbar
then under 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 which is said to be making the error is R.drawer.ic_drawer. How do I resolve it?
ActionBarDrawerToggle Constructor is as follow.
android.support.v7.app.ActionBarDrawerToggle.ActionBarDrawerToggle(Activity activity,
DrawerLayout drawerLayout,
Toolbar toolbar,
int openDrawerContentDescRes,
int closeDrawerContentDescRes)
You are passing R.drawable.ic_drawer
drawable instead of toolbar that's why you are getting this error.
Create a toolbar and add it as action bar and pass this toolbar to this constructor.
An alternative way to solve it, is to import import android.support.v4.widget.DrawerLayout
instead of import android.support.v7.widget.DrawerLayout
According to the google documentation here: http://developer.android.com/reference/android/support/v4/app/ActionBarDrawerToggle.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With