我创建了带有后退箭头的工具栏,单击不起作用
toolbar = FindViewById<Toolbar>(Resource.Id.toolbar2);
toolbar.NavigationClick += Back;
private void Back(object sender, Toolbar.NavigationClickEventArgs e)
{
Finish();
}
在您的 OnCreate 方法中执行以下操作:
ActionBar.SetHomeButtonEnabled(true);
ActionBar.SetDisplayHomeAsUpEnabled(true);
然后像这样重写 OnOptionsItemSelected 方法。
public override bool OnOptionsItemSelected(IMenuItem item)
{
switch (item.ItemId)
{
case Android.Resource.Id.Home:
Finish();
return true;
default:
return base.OnOptionsItemSelected(item);
}
}
如果您正在使用Xamarin.Android.Support.v7
the Android.Resource.Id.Home
应该Resource.Id.Home
.
另外,你只需要ActionBar.SetDisplayHomeAsUpEnabled(true);
要显示主页按钮,无需调用 ButtonEnabled。
OnCreate 中是这样的:
Toolbar toolbar = FindViewById<Toolbar>(Resource.Id.toolbarID);
SetSupportActionBar(toolbar);
SupportActionBar.SetDisplayHomeAsUpEnabled(true);
OnOptionsItemSelected 中类似这样的内容:
public override bool OnOptionsItemSelected(IMenuItem item)
{
switch (item.ItemId)
{
case Android.Resource.Id.Home:
Finish();
return true;
default:
return base.OnOptionsItemSelected(item);
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)