Determine if NavigationDrawer is opening or closing

Is there any way to determine if the navigation box opens or closes? I read about the isDrawerOpen() and isDrawerVisible() methods, but they only return true if the navigation box is open or displayed accordingly.

I also read about the onDrawerSlide(View drawerView, float slideOffset) , which is called when the box is moved. slideOffset is a floating value from 0 to 1 that indicates the position of the box. But even this is caused when the drawer opens closing and .

I need to do something to do something only when opening a box, but not when closing, something tells me that I need to use the onDrawerSlide(View drawerView, float slideOffset) method onDrawerSlide(View drawerView, float slideOffset) , but I just can’t understand how to check this opens and does not close.

thanks

+6
source share
2 answers

To track the last value, use the ...

 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) {} }); 
+14
source

If you are using ActionBar ovveride ActionBarDrawerToggle

Further reading: Listen to public and private events on developer.android.com

0
source

All Articles