Sara Lince Sara Lince - 1 month ago 14
Android Question

DrawerLayout.DrawerListener - Detect Gravity Right/Left

I'm using a Drawerlayout that can be opened and closed from both sides (left and right) like this:

drawer.openDrawer(Gravity.LEFT);
drawer.openDrawer(Gravity.RIGHT);


I added a DrawerListener to detect when it's being closed:

drawer.addDrawerListener(new DrawerLayout.DrawerListener() {
@Override
public void onDrawerSlide(View drawerView, float slideOffset) {

}

@Override
public void onDrawerOpened(View drawerView) {

}

@Override
public void onDrawerClosed(View drawerView) {

Toast.makeText(activity, "closed",
Toast.LENGTH_LONG).show();
}

@Override
public void onDrawerStateChanged(int newState) {

}
});


Is there a way to find out if it was the left or the right drawer that got closed?

Thanks!

Answer

In the method onDrawerClosed there is a View named drawerView coming as the argument just check the id of that with your navigationViews ID then you can tell wich one triggered this listener .