Is there any way for me to determine whether the navigation drawer is opening or closing? I have read about isDrawerOpen()
and isDrawerVisible()
methods, but they only return true if the navigation drawer is opened or is visible respectively.
I also read about onDrawerSlide(View drawerView, float slideOffset)
method which gets called when the drawer is moving. The slideOffset
is the floating value between 0 and 1 telling which position the drawer is at now. But even that gets called when the drawer is opening and closing.
What I need to do is, to do something only when the drawer is opening but not when closing, something tells me that I have to use onDrawerSlide(View drawerView, float slideOffset)
method, but I just can't figure out how to check if it is opening and is not closing.
Thank you
Just add closeDrawer() inside onNavigationItemSelected() to close the drawer on selecting any item on Navigation Drawer.
The navigation drawer slides in from the left and contains the navigation destinations for the app. The user can view the navigation drawer when the user swipes a finger from the left edge of the activity. They can also find it from the home activity by tapping the app icon in the action bar.
To track the last value is an option ...
drawerLayout.setDrawerListener(new DrawerListener() {
private float last = 0;
@Override
public void onDrawerSlide(View arg0, float arg1) {
boolean opening = arg1>last;
boolean closing = arg1<last;
if(opening) {
Log.i("Drawer","opening");
} else if(closing) {
Log.i("Drawer","closing");
} else {
Log.i("Drawer","doing nothing");
}
last = arg1;
}
@Override public void onDrawerStateChanged(int arg0) {}
@Override public void onDrawerOpened(View arg0) {}
@Override public void onDrawerClosed(View arg0) {}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With