问题描述
这是很容易实现工具栏
与汉堡向后的箭头动画。在我看来这个动画是没有意义的,因为按材料设计规范抽屉式导航覆盖工具栏
打开时。我的问题是如何正确地禁用此动画,显示无论是汉堡包或后退箭头使用 getSupportActionBar()setDisplayHomeAsUpEnabled(真);
It's very easy to implement Toolbar
with hamburger to back arrow animation. In my opinion this animation is pointless because as per material design spec navigation drawer covers the Toolbar
when opened. My question is how to properly disable this animation and show either hamburger or back arrow using getSupportActionBar().setDisplayHomeAsUpEnabled(true);
这是我做到了,但它看起来像一个肮脏的黑客:
This is how I did it, but it looks like a dirty hack:
mDrawerToggle.setDrawerIndicatorEnabled(false);
if (showHomeAsUp) {
mDrawerToggle.setHomeAsUpIndicator(R.drawable.lib_ic_arrow_back_light);
mDrawerToggle.setToolbarNavigationClickListener(view -> finish());
} else {
mDrawerToggle.setHomeAsUpIndicator(R.drawable.lib_ic_menu_light);
mDrawerToggle.setToolbarNavigationClickListener(view -> toggleDrawer());
}
任何线索应如何正确实施只使用 setDisplayHomeAsUpEnabled
汉堡之间切换后退箭头图标?
Any clues how this should be properly implemented to use just setDisplayHomeAsUpEnabled
to switch between hamburger and back arrow icons?
推荐答案
这将禁用动画,创造drawerToggle时,覆盖onDrawerSlide():
This will disable the animation, when creating the drawerToggle, override onDrawerSlide():
drawerToggle = new ActionBarDrawerToggle(this, drawerLayout,
getToolbar(), R.string.open, R.string.close) {
@Override
public void onDrawerClosed(View view) {
super.onDrawerClosed(view);
}
@Override
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
}
@Override
public void onDrawerSlide(View drawerView, float slideOffset) {
super.onDrawerSlide(drawerView, 0); // this disables the animation
}
};
如果你想彻底删除的箭头,可以添加
If you want to remove the arrow completely, you can add
super.onDrawerSlide(drawerView, 0); // this disables the arrow @ completed state
在onDrawerOpened函数的末尾。
at the end of the onDrawerOpened function.
这篇关于禁止汉堡包回头箭动画工具栏上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!