gpt4 book ai didi

android - 抽屉导航 : no more animation on drawer icon when setting drawer listener

转载 作者:行者123 更新时间:2023-11-29 00:18:56 26 4
gpt4 key购买 nike

Drawer icon <-- 抽屉图标

如果您使用 android studio 创建一个带有抽屉导航的项目,当您打开/关闭抽屉时,抽屉图标会有流畅的动画效果。

如果我向我的抽屉布局添加一个抽屉监听器,则不再有动画,抽屉图标也不再改变:

DrawerLayout dl = (DrawerLayout) findViewById(R.id.drawer_layout);
dl.setDrawerListener(new ActionBarDrawerToggle(this, dl,R.drawable.ic_drawer,R.string.navigation_drawer_open,R.string.navigation_drawer_close));

我试图覆盖 ActionBarDrawerToggle 的方法以添加对 syncState() 的调用。

   DrawerLayout dl = (DrawerLayout)findViewById(R.id.drawer_layout);

mDrawerToggle = new ActionBarDrawerToggle(this, dl,
R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close) {

@Override
public void onDrawerSlide(View drawerView, float slideOffset) {
super.onDrawerSlide(drawerView, slideOffset);
mDrawerToggle.syncState();
}

@Override
public void onDrawerStateChanged(int newState) {
super.onDrawerStateChanged(newState);
mDrawerToggle.syncState();
}

public void onDrawerClosed(View view) {
super.onDrawerClosed(view);
mDrawerToggle.syncState();
}

/** Called when a drawer has settled in a completely open state. */
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
mDrawerToggle.syncState();
}
};
dl.setDrawerListener(mDrawerToggle);

现在,当抽屉打开时,我有一个小图标,然后当抽屉关闭时它会切换到一个大图标,但我没有流畅的动画。

有人知道如何获得流畅的动画吗?

最佳答案

尝试放置最后两个监听器缺少的 @Override 注释,并删除所有 syncState() 调用。从 Activity 的 onPostCreate 调用 syncState():

@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
// Sync the toggle state after onRestoreInstanceState has occurred.
mDrawerToggle.syncState();
}

关于android - 抽屉导航 : no more animation on drawer icon when setting drawer listener,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24387504/

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