android onOptionsMenuClosed 没有被子菜单调用

发布于 2024-09-19 06:47:11 字数 284 浏览 2 评论 0原文

我希望能够在用户退出选项菜单时自动取消暂停我的应用程序。 (当然,除非他们选择了暂停...)

处理onOptionsMenuClosed对于顶级菜单工作正常,但不会为子菜单调用。更高级别的 onPanelClosed 似乎也没有被调用。

我可以检测到他们何时进入菜单以及他们是否做出选择,但不能检测到他们是否只是点击菜单按钮退出。

我可以重写整个子菜单以使用对话框,但如果可以避免的话我宁愿不这样做。

有人有什么建议吗?

I want to be able to automatically unpause my app when the user exits from the options menu. (unless, of course, they have selected pause...)

Handling it onOptionsMenuClosed works fine for the top level menu but is not called for a submenu. The higher level onPanelClosed does not appear to be called either.

I can detect when they enter the menu and if they make a selection but not if they just hit the menu button to exit.

I could rewrite the whole submenu to use a dialog but I'd rather not if it can be avoided.

Does anyone have any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

闻呓 2024-09-26 06:47:12

您可以覆盖 onkeydown ,设置一个标志来检查菜单是否显示或不执行您的操作,然后返回 super.onKeyDown(keyCode, event); 。

您可以在每次按键时检查菜单是否在屏幕上。请记住其他按钮(“后退”、“搜索”和“主页”,然后触摸屏幕的其他部分可关闭菜单。)。使用其他按钮,您可以处理它们,但主页按钮和手指点击无法被覆盖。

如果我是你,我会忘记为此目的 @override ononkeydown 选项

但是你可以有 6 个菜单按钮,第 6 个称为“更多”,这可以创建一个自定义对话框,其中包含更多你可以处理的选项

You could override the onkeydown , set a flag to check if the menu is shown or not do you thing then return super.onKeyDown(keyCode, event); .

You could check if menu if on screen on every keydown.Keep in mind that other buttons (Back , search and home and touch on other part of the screen closes the menu.) .With other buttons you may do handle them but home botton and finger tap cannot be override.

If i was you i whould forget the @override on onkeydown option for that purpose

But you can have 6 menu buttons the 6th called "More" and that could create a custom dialog with more options that you can handle

£噩梦荏苒 2024-09-26 06:47:12

当检测到菜单按钮时,您可以重写 onKeyDown 并自己实现菜单。

You can override onKeyDown and implement a menu yourself when the menu button is detected.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文