ActionBarDrawerToggle 没有合适的可绘制构造函数 [英] ActionBarDrawerToggle No Suitable Constructor Drawable
问题描述
我有简单的代码来创建简单的导航抽屉,但是当我为 ActionBarDrawerToggle 声明参数时,它说无法应用可绘制图标...
I have simple code to create simple navigation drawer, but when i declare parameter for ActionBarDrawerToggle it's say that drawable icon cannot be applied...
Gradle 按摩构建
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)
我不知道我哪里做错了,我看到了 support/v7/widget/Toolbar 和 ActionBarDrawerToggle 但没有帮助
I dont know where i did wrong, i have see support/v7/widget/Toolbar and ActionBarDrawerToggle but no help
这是我的导入支持库
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;
这是我的 Build.Gradle(module:app) 依赖项
This my Build.Gradle(module:app) dependencies
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'
}
这是我的 ActionBarDrawerToggle 代码
This 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);
这是我的 Android Studio 图像
This my Android Studio image
推荐答案
有两个 ActionBarDrawerToggle 类.support.v4 和 support.v7's.然后,很混搭,v7的构造方法和v4的不一样.
There are two ActionBarDrawerToggle classes. The support.v4's and the support.v7's. Then, it is very cofusing, the v7's constructor methods are different from v4's.
您可以通过删除第三个参数 drawerImageRes 来修复它.
You may fix it simply by removing the third argument 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();
}
};
这篇关于ActionBarDrawerToggle 没有合适的可绘制构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!