gpt4 book ai didi

java - 如何部分禁用Android工具栏中的“主页”按钮单击?

转载 作者:行者123 更新时间:2023-12-02 13:16:37 24 4
gpt4 key购买 nike

我已经实现了onOptionsItemSelected来控制主页按钮:

override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
android.R.id.home -> {
if (mode) {
reset()
}
}
}
return super.onOptionsItemSelected(item)
}
现在,当我按主页时,我返回上一个片段。我需要的是,如果 mode为true,则在我单击home时仅触发 的 reset()函数,而无需返回上一个片段。如果错误,则只需返回即可。我该如何实现?

最佳答案

您应该返回true来告诉父项,该菜单项的单击已消耗。

override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
android.R.id.home -> {
if (mode) {
reset()
return true
}
}
}
return super.onOptionsItemSelected(item)
}

关于java - 如何部分禁用Android工具栏中的“主页”按钮单击?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63152979/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com