答案 0 :(得分:0)
首先,实现接口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);
}
注意:代码不完整,所以请告诉我是否有任何问题。