Sara Lince Sara Lince - 1 year ago 189
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:


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

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


public void onDrawerOpened(View drawerView) {


public void onDrawerClosed(View drawerView) {

Toast.makeText(activity, "closed",

public void onDrawerStateChanged(int newState) {


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


Answer Source

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 .

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download