ActionBarDrawerToggle No suitable Drawable constructor
I have some simple code to create a simple navigation drawer, but when I declare a parameter for ActionBarDrawerToggle it says that the shortcut cannot be used ...
Gradle Massages Build
Error:(36, 26) error: no suitable constructor found for
ActionBarDrawerToggle(MainActivity,DrawerLayout,int,int,int)
constructor ActionBarDrawerToggle.ActionBarDrawerToggle(Activity,DrawerLayout,Toolbar,int,int) is
not applicable
(argument mismatch; int cannot be converted to Toolbar)
constructor ActionBarDrawerToggle.
<T>ActionBarDrawerToggle(Activity,Toolbar,DrawerLayout,T,int,int) is not applicable
(cannot infer type-variable(s) T
(actual and formal argument lists differ in length))
where T is a type-variable:
T extends Drawable,DrawerToggle declared in constructor
<T>ActionBarDrawerToggle(Activity,Toolbar,DrawerLayout,T,int,int)
I don't know where I went wrong, I can see support / v7 / widget / Toolbar and ActionBarDrawerToggle but no help
I already liked this question and this
this is my import support library
import android.os.Bundle;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBarDrawerToggle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
These are my Build.Gradle dependencies (module: app)
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.android.support:support-v4:21.0.3'
}
This is my ActionBarDrawerToggle code
drawerListener = new ActionBarDrawerToggle(this, drawerLayout, R.drawable.ic_drawer,
R.string.drawer_open, R.string.drawer_close) {
@Override
public void onDrawerOpened(View drawerView) {
Toast.makeText(MainActivity.this, "Drawer Opened",
Toast.LENGTH_SHORT).show();
}
@Override
public void onDrawerClosed(View drawerView) {
Toast.makeText(MainActivity.this, "Drawer Closed",
Toast.LENGTH_SHORT).show();
}
};
drawerLayout.setDrawerListener(drawerListener);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
This my android studio image
+3
source to share
2 answers
There are two ActionBarDrawerToggle classes. support.v4 and support.v7 . Then, it's very cofusing, v7's constructor methods are different from v4's.
You can fix this simply by removing the third argument to drawerImageRes.
drawerListener = new ActionBarDrawerToggle(
this,
drawerLayout,
// R.drawable.ic_drawer, <== delete this argument
R.string.drawer_open,
R.string.drawer_close
) {
@Override
public void onDrawerOpened(View drawerView) {
Toast.makeText(MainActivity.this, "Drawer Opened",
Toast.LENGTH_SHORT).show();
}
@Override
public void onDrawerClosed(View drawerView) {
Toast.makeText(MainActivity.this, "Drawer Closed",
Toast.LENGTH_SHORT).show();
}
};
+23
source to share