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

查看:99
本文介绍了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.

但是您可以采用另一种方式.但是在那里,您必须自己对整个菜单进行编程.基本上将Menu添加到您的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天全站免登陆