首页 > 解决方案 > androidx.legacy.app.ActionBarDrawerToggle' 已弃用

问题描述

我使用 androidx 库,并且在以下代码中有 androidx.legacy.app.ActionBarDrawerToggle' is deprecated 错误:

private ActionBarDrawerToggle mDrawerToggle;

mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
        // associate Navigation Drawer with ActionBar
        mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
                R.drawable.ic_drawer, //nav menu toggle icon

我想如何改变它?我试图找到一个解决方案,但与 androidx 无关。我会简单地解释一下,因为我是 android 中的新手。

标签: androidandroidxactionbardrawertoggle

解决方案


更改 androidx。旧版.app.ActionBarDrawerToggle 到 androidx。appcompat .app.ActionBarDrawerToggle,即遗留给appcompat。

另外,请记住将您的工具栏添加为您的第三个参数。

文档可以在这里找到: https ://developer.android.com/reference/androidx/appcompat/app/ActionBarDrawerToggle


推荐阅读