安卓:我怎样才能设置一个监听器的菜单按钮? [英] Android: How can I set a listener to the MenuButton?
本文介绍了安卓:我怎样才能设置一个监听器的菜单按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望做一个自定义操作时,手机上的菜单pressing
按钮。
I want to do a custom action when pressing on the Menu
button on the phone.
是否有可能在按钮上设置onClickListener(或类似),如果是这样,怎么样?
Is it possible to set an onClickListener (or similar) on the button and if so, how?
onCreateOptionsMenu
只调用了第一次按钮pressed - 我已经试过这种
onCreateOptionsMenu
is only called the first time the button is pressed - I've already tried this.
推荐答案
通常你不应该重写菜单
行为,用户所期望出现的菜单,但是你可以使用的东西沿着这些路线:
Usually you shouldn't override MENU
behavior as users expect menu to appear, however you can use something along these lines:
/* (non-Javadoc)
* @see android.app.Activity#onKeyDown(int, android.view.KeyEvent)
*/
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ( keyCode == KeyEvent.KEYCODE_MENU ) {
Log.d(TAG, "MENU pressed");
return true;
}
return super.onKeyDown(keyCode, event);
}
这篇关于安卓:我怎样才能设置一个监听器的菜单按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文