Прежде всего, реализовать интерфейс DrawerLayout.IDrawerListener
.
private DrawerLayout drawer;
private ActionBarDrawerToggle toggle;
private NavigationView navigationView;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.activity_main);
Android.Support.V7.Widget.Toolbar toolbar = FindViewById<Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);
SetSupportActionBar(toolbar);
SupportActionBar.SetDisplayHomeAsUpEnabled(true);
drawer = FindViewById<DrawerLayout>(Resource.Id.drawer_layout);
toggle = new ActionBarDrawerToggle(this, drawer, Resource.String.navigation_drawer_open, Resource.String.navigation_drawer_close);
drawer.AddDrawerListener(toggle);
drawer.AddDrawerListener(this);
toggle.SyncState();
}
Теперь реализуем функции в упражнении:
public void OnDrawerClosed(View drawerView)
{
//Code here
((DrawerLayout.IDrawerListener)toggle).OnDrawerClosed(drawerView);
}
public void OnDrawerOpened(View drawerView)
{
//Code here
((DrawerLayout.IDrawerListener)toggle).OnDrawerOpened(drawerView);
}
public void OnDrawerSlide(View drawerView, float slideOffset)
{
//Code here
((DrawerLayout.IDrawerListener)toggle).OnDrawerSlide(drawerView, slideOffset);
}
public void OnDrawerStateChanged(int newState)
{
//Code here
((DrawerLayout.IDrawerListener)toggle).OnDrawerStateChanged(newState);
}
Примечание. Код не полный, поэтому сообщите мне, если возникнут какие-либо проблемы.