我试图在我的应用程序中实现android.support.v4.app.actionBarDrawerToggle;因为这个类已被弃用
此类已弃用。请使用ActionBarDrawerToggle
支持-v7-appcompat。
我已经切换到android.support.v7.app.actionBarDrawerToggle。
在我以这种方式调用构造函数之前:

mDrawerToggle = new ActionBarDrawerToggle(
            this,                  /* host Activity */
            mDrawerLayout,         /* DrawerLayout object */
            R.drawable.ic_drawer,  /* nav drawer image to replace 'Up' caret */
            R.string.drawer_open,  /* "open drawer" description for accessibility */
            R.string.drawer_close  /* "close drawer" description for accessibility */
        ){
        public void onDrawerClosed(View view) {
            getActionBar().setTitle(mTitle);
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }

        public void onDrawerOpened(View drawerView) {
            getActionBar().setTitle(mDrawerTitle);
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }
    };

但是在我切换到新的v7支持库之后,我收到了一个错误
"ActionBarDrawerToggle() in ActionBarDrawerToggle cannot be applied to:

toolbar: android.support.v7.widget.Toolbar
Actual arguments: R.drawable.ic_drawer (int)"

显然,我没有在构造函数中引入一个合适的工具栏,但我不确定是否理解这两个冲突参数之间的区别。如何获取所需的工具栏?

最佳答案

我通过导入较新的android.support.v7.app.ActionBarDrawerToggle并使用recyclerview而不是listview解决了我的问题,如本例所示:How to make Material Design Navigation Drawer With Header View

private ActionBarDrawerToggle mDrawerToggle;
//... ...
mDrawerToggle = new ActionBarDrawerToggle(
            this,
            mDrawerLayout,
            toolbar,
            R.string.drawer_open, R.string.drawer_close){
                    @Override
                    public void onDrawerOpened(View drawerView) {
                        super.onDrawerOpened(drawerView);
                        // code here will execute once the drawer is opened
                        getSupportActionBar().setTitle(mTitle);
                        invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
                    }
                    @Override
                    public void onDrawerClosed(View drawerView) {
                        super.onDrawerClosed(drawerView);
                        // Code here will execute once drawer is closed
                        getSupportActionBar().setTitle(mDrawerTitle);
                        invalidateOptionsMenu();
    };

如果您仍然有问题,请检查这里:
How to replace deprecated android.support.v4.app.ActionBarDrawerToggle

08-06 11:49