【发布时间】:2015-02-24 10:42:06
【问题描述】:
我试图在我的应用中实现 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)"
显然我没有在构造函数中引入适当的工具栏,但我不确定理解这两个冲突参数之间的区别。如何获得所需的工具栏?
【问题讨论】:
-
我支持这个问题。我发现这是部分解决方案: getActionBar().setDisplayShowHomeEnabled(true); getActionBar().setIcon(R.drawable.ic_drawer);问题是图标有填充 - 我怎样才能删除它?另外 - 我在哪里可以找到一个好的 ic_drawer.png?
-
同时这个问题在stackoverflow.com/questions/26439619/…得到了回答
标签: android navigation-drawer actionbardrawertoggle