抓住关键preSS采用Android [英] Catch keypress with android
问题描述
我如何能赶上手机上的键preSS的Android SDK?我一直在四处寻找了几个小时没有发现任何东西。
How can i catch a phone keypress with the android SDK? i've been looking around for hours without finding anything..
例如:
在某些情况下,我要赶消息,当用户presses手机上的挂断按钮,然后在它到达OS丢弃这个消息。
In some cases, i want to catch the message when a user presses the "hang up" button on the phone, and then discard the message before it reaches the OS.
这可能吗?
推荐答案
您可以处理来自视图或一般为您的整个应用的关键事件:
You can either handle key events from a view or in general for your whole application:
从视图句柄onKey:
Handle onKey from a View:
public boolean onKey(View v, int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_ENTER:
/* This is a sample for handling the Enter button */
return true;
}
return false;
}
记住落实OnKeyListener并设置你的听众 YourView.setOnKeyListener(本);
第二种可能是:
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_MENU:
/* Sample for handling the Menu button globally */
return true;
}
return false;
}
您也可以TA一起来看看的onkeyup
。
You could also ta a look at onKeyUp
.
资源:<一href="http://developer.android.com/reference/android/view/View.html">http://developer.android.com/reference/android/view/View.html
在这里,你可以看到一个列表的所有的KeyEvents
And here you can see a list with all KeyEvents
这篇关于抓住关键preSS采用Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!