How can I use button to show/hide Navigation Drawer, I have used this SO link to create and manage Navigation Drawer.
Now i am using (Swipe to right from left - to show)
to Close Drawer:
drawer.CloseDrawer((int)GravityFlags.Left);
to Open Drawer:
drawer.OpenDrawer((int)GravityFlags.Left);
If you are using Sliding Drawer Menu, and you want to hide the menu when it is open (when drag from right to left). Then we have to deal with listview object ontouch listener. The code will be like this.
//((( When we drage from Right to left then menu hide ))))
lvMenu.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction())
{
case MotionEvent.ACTION_DOWN:
toggleMenu(v);
break;
case MotionEvent.ACTION_UP:
//showtoast("up");
break;
default:
return false;
}
return false;
}
});
public void toggleMenu(View v) {
mLayout.toggleMenu();
}
For complete code, you can put the comment here, if you have any problem
Grab a reference to the DrawerLayout
and call closeDrawer(int) to close it and openDrawer(int) to open it. The int
parameter refers to the gravity. In your case it should be GravityCompat.LEFT
/ GravityCompat.START
, because accordingly to the screenshot you posted, your DrawerLayout
open and close on the left.
To open the Drawer
DrawerLayout drawer = findViewById(R.id.drawer_layout);
drawer.openDrawer(GravityCompat.START);
To close the drawer
DrawerLayout drawer = findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);