检测菜单按钮是pressed第二次 [英] Detecting menu button being pressed a second time

查看:158
本文介绍了检测菜单按钮是pressed第二次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的code想要一个特定标志,当菜单在屏幕上进行设置。我试图抓住关键code ==中的onkeydown KeyEvent.KEY code_MENU事件来检测时,菜单将显示 - 但是如果菜单按钮为pressed第二次(使菜单消失),没有钥匙code == KeyEvent.KEY code_MENU事件。

I am wanting a certain flag in my code to be set when a menu is on screen. I tried catching the keyCode == KeyEvent.KEYCODE_MENU event in onKeyDown to detect when the menu would appear - but then if the menu button is pressed a second time (making the menu disappear), there is no keyCode == KeyEvent.KEYCODE_MENU event.

我应该寻找一些其他的活动,或者是有测试如果某种菜单上显示功能?

Should I look for some other event, or is there a function to test if some kind of menu is on display?

推荐答案

要赶上菜单被打开,则可以覆盖

To catch the menu being opened, you can override

public boolean onPrepareOptionsMenu(Menu menu)

要赶上菜单被关闭,你可以覆盖

To catch the menu being closed, you can override

public void onOptionsMenuClosed(Menu menu)

不过请记住,第二个将被称为既当用户presses菜单按钮,第二次或水龙头的菜单选项之一。因此,你需要结合

However keep in mind that the second one will be called both when the user presses "menu" button the second time or taps one of the menu options. Therefore you'll need to use it in combination with

public boolean onOptionsItemSelected(MenuItem item)

这篇关于检测菜单按钮是pressed第二次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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