Reputation: 211
I have a NavigationDrawer
on my Main and when I press the Back button (with the NavigationDrawer
open) the application quits, I want it to just close the NavigationDrawer
. In Java, Android has this:
@Override
public void onBackPressed()
{
if (DrawerLayout.isDrawerOpen(Gravity.START))
DrawerLayout.closeDrawer(Gravity.START);
else
super.onBackPressed();
}
How to make this in Xamarin.Android?
Upvotes: 1
Views: 629
Reputation: 4953
just delegate the method like this:
drawerLayout = FindViewById<DrawerLayout>(Resource.Id.drawerLayoutID);
drawerLayout.DrawerOpened += delegate
{
//code when drawer is opened!
};
Upvotes: 1
Reputation: 428
Try this code:
public override void OnBackPressed()
{
//if (drawerLayout.IsDrawerOpen(YourNavigationView))
if (drawerLayout.IsDrawerOpen(Android.Support.V4.View.GravityCompat.Start))
{
drawerLayout.CloseDrawers();
// or
//drawerLayout.CloseDrawer(Android.Support.V4.View.GravityCompat.Start);
//drawerLayout.CloseDrawer(navigationView);
}
else
base.OnBackPressed();
}
Upvotes: 2