[英]How to partially disable click on home button in Android toolbar?
我已经实现了onOptionsItemSelected
来控制主页按钮:
override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
android.R.id.home -> {
if (mode) {
reset()
}
}
}
return super.onOptionsItemSelected(item)
}
现在,当我按下 home 键时,我 go 回到了之前的片段。 我需要的是,如果mode
为真,当我点击主页时,只触发reset()
function 而不会返回到上一个片段。 如果它是假的,只需返回 go。 我怎样才能做到这一点?
您应该返回true
以表明菜单项上的点击已被消耗。
override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
android.R.id.home -> {
if (mode) {
reset()
return true
}
}
}
return super.onOptionsItemSelected(item)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.