且构网

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

Android-保持选项菜单打开

更新时间:2022-03-28 22:39:56

使用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.