且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Android - 保持选项菜单打开

更新时间:2022-11-16 17:26:05

这对于 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.