如何处理传入我的Android应用程序的触摸事件的所有输入键?
我能抓住所有这些活动吗?
答案 0 :(得分:1)
检查这些:
http://developer.android.com/reference/android/view/View.OnTouchListener.html
http://developer.android.com/reference/android/view/View.OnKeyListener.html
答案 1 :(得分:1)
只需将以下内容添加到您的初始活动中:
// generic Key Listener
public boolean onKeyDown(int keyCode, KeyEvent event)
{
Log.d("Activity", "Key pressed"+keyCode);
switch (keyCode)
{
case KeyEvent.KEYCODE_BACK:
Log.d("Activity", "Back Key pressed");
return true;
case KeyEvent.KEYCODE_MENU:
Log.d("Activity", "Menu Key pressed");
return true;
case KeyEvent.KEYCODE_HOME:
Log.d("Activity", "Home Key pressed"); // doesn't Print!
return true;
}
return super.onKeyDown(keyCode, event);
}
注意,您无法捕获Home键!