Android - 保持选项菜单打开 [英] Android - keep options menu open

查看:22
本文介绍了Android - 保持选项菜单打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的 Android 应用程序中启动并运行了一个选项菜单,我已经覆盖了 onCreateOptionsMenu、onOptionsItemSelected 和 onPrepareOptionsMenu 方法来稍微自定义菜单.

I have an Options menu up and running in my Android application and I've overridden the onCreateOptionsMenu, onOptionsItemSelected and onPrepareOptionsMenu methods to customize the menu a little.

我的问题与在用户单击菜单项后保持选项菜单打开有关.基本上,我希望能够隐藏菜单,直到用户单击设备菜单键.一旦用户单击此键,我希望能够将菜单固定到位,而不管用户单击菜单项多少次.如果用户想要隐藏选项菜单,他们只需要再次点击设备菜单键.

My question is related to keeping the Options menu open after the user clicks on a menu item. Basically, I'd like to be able to hide the menu until the user clicks on the device menu key. Once the user clicks on this key, I'd like to be able to hold the menu in place regardless of how many times the user clicks on menu items. If the user wants to hide the Options menu, they'd just need to click on the device menu key again.

是否支持(甚至建议)这种类型的交互.如果不支持此交互,我们非常欢迎您提供任何替代建议.

Is this type of interaction supported (or even advisable). If this interaction is not supported, any alternative suggestions are more than welcome.

干杯!

肖恩

推荐答案

这对于 onCreateOptionsMenu 和其他方法是不可能的.他们总是那样做.

This will not be possible with onCreateOptionsMenu and the other methods. They always act that way.

但是你可以用另一种方式来做.但是你必须自己编程整个菜单.基本上在 layout.xml 中添加菜单并隐藏它(可见性 = 消失).然后覆盖 onKeyDown 的方法.在那里你检查它是否是菜单键.如果菜单尚未打开是,则显示菜单.如果它已经打开,你就隐藏它.

But you can do it another way. But there you have to program the whole menu yourself. Basically add the Menu in your layout.xml and let it be hidden (visibility = gone). Then you overwrite the methods onKeyDown. There you check if it is the Menu key. if the menu is not yet open yes, then you show the menu. If it is open already, you hide it.

应该不会太难.好消息是,您可以使菜单看起来完全符合您的要求,并让它按照您希望的方式做出反应.

should not be too difficult. Good thing as well is, that you can make the menu look exactly the way you want and as well let it react the way you want.

这篇关于Android - 保持选项菜单打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆