ActionBarDrawerToggle没有合适的构造函数可绘

ActionBarDrawerToggle没有合适的构造函数可绘

本文介绍了ActionBarDrawerToggle没有合适的构造函数可绘制对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有简单的code创建简单的导航抽屉里,但是当我宣布参数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...

摇篮按摩构建

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)

我不知道我做错了,我已经看到支持/ V7 /空间/工具栏 ActionBarDrawerToggle 但没有帮助

我已经不喜欢this问题和this

这是我的导入支持库

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(模块:应用程序)的依赖

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 code

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);

这是我的机器人工作室

推荐答案

有两种ActionBarDrawerToggle类。该support.v4's而support.v7's.那么,这是非常cofusing时,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没有合适的构造函数可绘制对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 14:34