Skip to content

Instantly share code, notes, and snippets.

@espritm
Last active March 28, 2017 14:37
Show Gist options
  • Save espritm/2422b67faeb2609d4d09255daac0aa9f to your computer and use it in GitHub Desktop.
Save espritm/2422b67faeb2609d4d09255daac0aa9f to your computer and use it in GitHub Desktop.
public class MainActivity : AppCompatActivity
{
DrawerLayout m_drawerLayout;
NavigationView m_navigationView;
protected override void OnCreate(Bundle bundle)
{
//...
m_drawerLayout = FindViewById<DrawerLayout>(Resource.Id.maintActivity_drawerlayout);
m_navigationView = FindViewById<NavigationView>(Resource.Id.maintActivity_navigationView);
//Handle NavigationView's item click
m_navigationView.NavigationItemSelected += M_navigationView_NavigationItemSelected;
}
public override bool OnOptionsItemSelected(IMenuItem item)
{
switch (item.ItemId)
{
//...
//Handle sandwich menu icon click
case Android.Resource.Id.Home:
//If menu is open, close it. Else, open it.
if (m_drawerLayout.IsDrawerOpen(GravityCompat.Start))
m_drawerLayout.CloseDrawers();
else
m_drawerLayout.OpenDrawer(GravityCompat.Start);
break;
}
return base.OnOptionsItemSelected(item);
}
private void M_navigationView_NavigationItemSelected(object sender, NavigationView.NavigationItemSelectedEventArgs e)
{
switch (e.MenuItem.ItemId)
{
case Resource.Id.leftmenu_profile:
break;
case Resource.Id.leftmenu_shopping_list:
break;
case Resource.Id.leftmenu_favorites:
break;
case Resource.Id.leftmenu_params_option:
break;
case Resource.Id.leftmenu_params_about:
break;
}
m_drawerLayout.CloseDrawer(GravityCompat.Start);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment