gpt4 book ai didi

android - 弃用的 ActionBarDrawerToggle

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:53:09 25 4
gpt4 key购买 nike

我试图在我的应用中实现 android.support.v4.app.ActionBarDrawerToggle;因为这个类被弃用了

This class is deprecated. Please use ActionBarDrawerToggle in support-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

关于android - 弃用的 ActionBarDrawerToggle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28693608/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com