简体   繁体   English

实施导航抽屉在操作栏上

[英]Implementing navigation drawer On the action bar

Guys I am implementing the navigation drawer on the action bar i am getting an error the error is 伙计们,我正在操作栏上实现导航抽屉,但出现错误,错误是

'ActionBarDrawerToggle(android.app.Activity, android.support.v4.widget.DrawerLayout, android.support.v7.widget.Toolbar, int, int)' in 'android.support.v7.app.ActionBarDrawerToggle' cannot be applied to '(com.example.samsung.getstarted.MainActivity, android.support.v4.widget.DrawerLayout, int, int, int)' 无法将'android.support.v7.app.ActionBarDrawerToggle'中的'ActionBarDrawerToggle(android.app.Activity,android.support.v4.widget.DrawerLayout,android.support.v7.widget.Toolbar,int,int)' '(com.example.samsung.getstarted.MainActivity,android.support.v4.widget.DrawerLayout,int,int,int)'

my code is 我的代码是

private DrawerLayout.DrawerListener createDrawerToggle() {
    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close) {

        @Override
        public void onDrawerClosed(View view) {
            super.onDrawerClosed(view);
        }

        @Override
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
        }

        @Override
        public void onDrawerStateChanged(int state) {
        }
    };
    return mDrawerToggle;
}

please help me in solving this 请帮助我解决这个问题

It is because you are using a different version of DrawerLayout. 这是因为您使用的是其他版本的DrawerLayout。 Delete the 删除

import android.support.v4.widget.DrawerLayout;

android import again. android再次导入。

Problem is this line code: 问题是此行代码:

mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close) 
{
}

you have import android.support.v7.app.ActionBarDrawerToggle , so you should use constructor as: 您已经导入了android.support.v7.app.ActionBarDrawerToggle ,因此应将构造函数用作:

ActionBarDrawerToggle(Activity activity, DrawerLayout drawerLayout, int openDrawerContentDescRes, int closeDrawerContentDescRes) 

or 

ActionBarDrawerToggle(Activity activity, DrawerLayout drawerLayout, Toolbar toolbar, int openDrawerContentDescRes, int closeDrawerContentDescRes) 

So for your case, just remove R.drawable.ic_drawer from your instantiation. 因此,对于您的情况,只需从实例化中删除R.drawable.ic_drawer

Otherwise you could change the import for ActionBarDrawerToggle with V4, but it is already deprecated. 否则,您可以使用V4更改ActionBarDrawerToggle的导入,但已不建议使用。

Hope this help! 希望对您有所帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM