【发布时间】:2025-11-28 04:45:01
【问题描述】:
如果你用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);
现在,当抽屉打开时,我有一个小图标,然后在抽屉关闭时切换为大图标,但我没有流畅的动画。
有人知道如何获得流畅的动画吗?
【问题讨论】:
标签: android animation android-actionbar navigation-drawer