简体   繁体   中英

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

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. Delete the

import android.support.v4.widget.DrawerLayout;

android import again.

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:

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.

Otherwise you could change the import for ActionBarDrawerToggle with V4, but it is already deprecated.

Hope this help!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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