Android常用的物理按鍵
- KEYCODE_POWER 電源鍵
- KEYCODE_MENU 菜單鍵
- KEYCODE_BACK 后退鍵
- KEYCODE_HOME Home鍵
- KEYCODE_VOLUME_UP 音量鍵+
- KEYCODE_VOLUME_DOWN 音量鍵-
- KEYCODE_DPAD_CENTER/KEYCODE_ENTER 確認(rèn)鍵
- KEYCODE_DPAD_UP 向上
- KEYCODE_DPAD_DOWN 向下
- KEYCODE_DPAD_LEFT 向左
- KEYCODE_DPAD_RIGHT 向右
- KEYCODE_0 ~ KEYCODE_9 數(shù)字鍵
- KEYCODE_A ~ KEYCODE_Z 字母鍵
常用回調(diào)監(jiān)聽
onKeyUp(int keyCode, KeyEvent event);
onKeyLongPress(int keyCode, KeyEvent event)缸浦;
dispatchKeyEvent(KeyEvent event) 剪廉;
onKeyDown(int keyCode, KeyEvent event)占锯;
如下:
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_DPAD_CENTER:
break;
case KeyEvent.KEYCODE_ENTER:
break;
case KeyEvent.KEYCODE_BACK:
break;
case KeyEvent.KEYCODE_DPAD_RIGHT:
return false;
case KeyEvent.KEYCODE_DPAD_LEFT:
return false;
case KeyEvent.KEYCODE_0:
break;
case KeyEvent.KEYCODE_1:
break;
case KeyEvent.KEYCODE_2:
break;
case KeyEvent.KEYCODE_3:
break;
case KeyEvent.KEYCODE_4:
break;
case KeyEvent.KEYCODE_5:
break;
case KeyEvent.KEYCODE_6:
break;
case KeyEvent.KEYCODE_7:
break;
case KeyEvent.KEYCODE_8:
break;
case KeyEvent.KEYCODE_9:
break;
}
return super.onKeyDown(keyCode, event);
}
該方法的返回值為一個(gè)boolean類型的變量,當(dāng)返回true時(shí)划煮,表示已經(jīng)處理完了這個(gè)事件,不再繼續(xù)進(jìn)行處理;而當(dāng)返回false時(shí)挫掏,表示并沒(méi)有處理完該事件,將繼續(xù)對(duì)其進(jìn)行處理喷舀。