我已经实现了与父高相匹配的导航抽屉。现在我认为点击汉堡包抽屉按钮后显示的后退箭头按钮实际上是必要的,因为我无法点击它,因为我的导航抽屉一旦显示就超过了工具栏。
我实际上并不想要那个按钮动画,那么我怎样才能让汉堡包抽屉按钮保持不变而不转向后箭头?我需要代码和解释。谢谢!
NavigationView
<android.support.design.widget.NavigationView
android:id="@+id/navigation"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:menu="@menu/navigation_menu"/>
MainActivity
@Override
protected void onCreate(Bundle savedInstanceState) {
...
// Drawer
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.activity_main);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, R.string.navigation_open, R.string.navigation_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
}
答案 0 :(得分:3)
在Google IO 2017上引入了此API,可从支持库版本25.3.0获得。
// Install drawer toggle
drawerToggle = new ActionBarDrawerToggle(this, drawerLayout,
R.string.drawer_open, R.string.drawer_close);
// Disable animation
drawerToggle.setDrawerSlideAnimationEnabled(false);
这将使抽屉箭头不会被动画化。
确切地说,答案 1 :(得分:0)
在你的Drawer Layout所在的布局中,在他们和内部工具栏上放置一个android.support.v7.widget.Toolbar,在左边放一个ImageView,然后点击该imageview检查抽屉是否打开,然后关闭它,反之亦然
像这样:
if (drawerLayout.isDrawerOpen(GravityCompat.START)) {
drawerLayout.closeDrawer(GravityCompat.START);
} else {
drawerLayout.openDrawer(GravityCompat.START);
}
答案 2 :(得分:0)
在onDrawerSlide()方法中禁用supper调用。它将停止箭头和汉堡之间的动画:
ActionBarDrawerToggle drawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, toolbar, "Open navigation drawer", "Close navigation drawer") {
@Override
public void onDrawerClosed(View drawerView) {
super.onDrawerClosed(drawerView);
}
@Override
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
}
@Override
public void onDrawerSlide(View drawerView, float slideOffset) {
// Do nothing Here
}
};
// Set the drawer toggle as the DrawerListener
mDrawerLayout.setDrawerListener(drawerToggle);