1

I need to open drawer using fab button.
I have the following code and all that i need is to make drawer open

public Action<object, EventArgs> Clicked { get; set; }

private event EventHandler FabClicked = delegate { };

private async void OnFabClicked(object sender, EventArgs args)
{
    var drawer = FindViewById<DrawerLayout>(Resource.Id.drawer_layout);
    // open drawer
}
ToolmakerSteve
  • 18,547
  • 14
  • 94
  • 196
  • Does [this android/java Q&A](https://stackoverflow.com/q/19442841/199364) help? If you are able to adapt one of those answers, to work in Xamarin.Android, please add an answer below ,showing the working code. This will help anyone else who is using Xamarin.Android instead of java. – ToolmakerSteve Jul 10 '21 at 14:31
  • Also, here is a [Xamarin.Android Sample](https://learn.microsoft.com/en-us/samples/xamarin/monodroid-samples/android50-navigationdrawer/) which shows how to work with the navigation drawer. – ToolmakerSteve Jul 10 '21 at 14:33
  • Here is [Android dev doc for DrawerLayout](https://developer.android.com/reference/kotlin/androidx/drawerlayout/widget/DrawerLayout). Though as a Xamarin developer myself, it would not be easy for me to find, in that lengthy java-based document, the "openDrawer" method, if I didn't already know it existed! – ToolmakerSteve Jul 10 '21 at 14:42

1 Answers1

1

Use OpenDrawer method , refer to https://stackoverflow.com/a/49790329/8187800.

private async void OnFabClicked(object sender, EventArgs args)
{
    var drawer = FindViewById<DrawerLayout>(Resource.Id.drawer_layout);
    // open drawer

    drawer.OpenDrawer(GravityCompat.Start);
}
ColeX
  • 14,062
  • 5
  • 43
  • 240