在activity类中,我将actionbar设置为:
我的活动
setSupportActionBar(findViewById(R.id.toolbar_my))
supportActionBar?.apply {
setDisplayHomeAsUpEnabled(true)
setDisplayShowHomeEnabled(true)
}
因为我需要重写
onOptionsItemSelected(...)
(在fragment类中),我没有重写
onSupportNavigateUp()
在这里
这项活动是一个片段。我想要的是,当单击actionbar向上按钮时,除了弹出,还要撤销一个自定义的save()方法。
所以在片段的
onOptionsItemSelected(…)
,为
item.id == android.R.id.home
案例然而,我在这里做了一个转折点,发现当单击向上/主页按钮时
android.R.id.home
案件从未撤销。所选方法上的其他项有效。
在fragment类中:
我的片段
override fun onOptionsItemSelected(item: MenuItem?): Boolean {
when (item?.itemId) {
android.R.id.home -> {
// code here not gets called when click up/home button
mPresenter.save()
return true
}
R.id.edit-> {
// The code here is revoked when item selected.
}
else -> {
return super.onOptionsItemSelected(item)
}
}
}
我试图覆盖另一个
onOptionsItemSelected(…)
方法,并写入
安卓R、 id.主页
情况下,仍然无法调用其中的方法。
为什么代码在
项目id==android。R、 id.主页
案例未调用?