Android 按键监听

 @Override
 public boolean onKeyDown(int keyCode, KeyEvent   event)
 {
  if(keyCode ==   KeyEvent.KEYCODE_BACK)
  {
   return   true;
  }  
  if(keyCode ==   KeyEvent.KEYCODE_VOLUME_DOWN)
  {
   return   true;
  }  
  if(keyCode ==   KeyEvent.KEYCODE_VOLUME_UP)
  {
   return   true;
  }  
  if(keyCode ==   KeyEvent.KEYCODE_SEARCH)
  {
   return   true;
  }  
  if(keyCode ==   KeyEvent.KEYCODE_MENU)
  {
   return   true;
  }
  return super.onKeyDown(keyCode,   event);
 }

注: 该方法不能截获HOME键,且只能截获当前Activity的按键事件

你可能感兴趣的:(Andorid)