我只有 Activity,它是 ActionBarActivity 类的子级。在方法中我设置OnCreate支持工具栏。为此,我重写了 OnOptionsItemSelected,因此当我按下后退按钮时执行了一些操作
代码如下所示:
[Activity (Label = "SimplyActivity", Theme="@style/MyTheme")]
public class SimplyActivity : ActionBarActivity
{
private Toolbar toolbar;
// ... OnCreate method
this.toolbar = FindViewById<Toolbar>(Resource.Id.toolbar);
SetSupportActionBar (this.toolbar);
SupportActionBar.SetDisplayHomeAsUpEnabled (true);
SupportActionBar.SetHomeButtonEnabled (true);
public override bool OnOptionsItemSelected (IMenuItem item)
{
if (item.TitleFormatted == null) this.OnBackPressed ();
return base.OnOptionsItemSelected (item);
}
不幸的是,只要工具栏显示正确,按下回键时就不再有任何反应。我想补充一点,在其他活动(使用片段)中一切正常。
请帮我
它应该像这样工作
public override bool OnOptionsItemSelected(IMenuItem item)
{
//Back button pressed -> toggle event
if (item.ItemId == Android.Resource.Id.Home)
this.OnBackPressed();
return base.OnOptionsItemSelected(item);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)