@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
switch (keyCode) {
case KeyEvent.KEYCODE_MENU:
Log.d(TAG, "KeyEvent.KEYCODE_MENU");
Toast.makeText(this, "KeyEvent.KEYCODE_MENU", Toast.LENGTH_LONG);
break;

case KeyEvent.KEYCODE_HOME:
Log.d(TAG, "KeyEvent.KEYCODE_HOME");
// finish();
android.os.Process.killProcess(android.os.Process.myPid());
Toast.makeText(this, "KeyEvent.KEYCODE_HOME", Toast.LENGTH_LONG);
break;

case KeyEvent.KEYCODE_BACK:
Log.d(TAG, "KeyEvent.KEYCODE_BACK");
// finish();
Toast.makeText(this, "KeyEvent.KEYCODE_BACK", Toast.LENGTH_LONG);
break;

case KeyEvent.KEYCODE_VOLUME_DOWN:
Log.d(TAG, "KeyEvent.KEYCODE_VOLUME_DOWN");
break;

case KeyEvent.KEYCODE_VOLUME_UP:
Log.d(TAG, "KeyEvent.KEYCODE_VOLUME_UP");
break;

case KeyEvent.KEYCODE_POWER:
Log.d(TAG, "KeyEvent.KEYCODE_POWER");
break;

default:
Log.d(TAG, "没有匹配的");
break;
}

return super.onKeyDown(keyCode, event);
}

// test for combination key
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
int keyCode = event.getKeyCode();
if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN &&
keyCode == KeyEvent.KEYCODE_POWER) {
Log.d(TAG, "VOLUME_DOWN + POWER is pressed");
// finish();
// return true;
}
//else
// return false;
return super.dispatchKeyEvent(event);
}

//当按键弹起时发生的事件
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_ALT_LEFT:
break;

default:
break;
}
return super.onKeyUp(keyCode, event);
}

//触摸屏事件,当用手或者用笔在触摸屏上做动作是发生
@Override
public boolean onTouchEvent(MotionEvent event) {
int iAction = event.getAction();
if (iAction == MotionEvent.ACTION_MOVE) {
Log.d(TAG, "你在触摸屏上进行了滑动");
}
return super.onTouchEvent(event);
}

//连续点击按键时发生的事件
@Override
public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) {
// TODO Auto-generated method stub
return super.onKeyMultiple(keyCode, repeatCount, event);
}

// 长按某键
@Override
public boolean onKeyLongPress(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
//TODO
}
return super.onKeyLongPress(keyCode, event);
}

更多相关文章

  1. Android(安卓)ListView列表分组
  2. android >ToggleButton(开启/关闭) 控件
  3. Android错误汇总集锦
  4. android listview check 事件
  5. Android锁屏及监听锁屏事件
  6. Android点击事件onTouchEvent与onInterceptTouchEvent传递关系-
  7. Android(安卓)7.0 SystemUI Recent浅析
  8. 判断android设备是否支持多点触控
  9. android Menu 菜单使用总结

随机推荐

  1. Android 封装自己的工具Jar
  2. Android P 系统启动-System Server启动篇
  3. sdut 2162:The Android University ACM T
  4. Android(安卓)Studio开发之 JNI 篇的简单
  5. android设置Webview的滚动条属性
  6. Android(安卓)自己画View设置画笔的颜色
  7. android 导出jar包并使用
  8. Android中intent如何传递自定义数据类型
  9. Android开发_精准排布控件位置
  10. Android 图片Bitmap的剪切