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的按键事件
标签:event,return,KeyEvent,KEYCODE,监听,按键,Android,true,keyCode 来源: https://blog.51cto.com/u_15298588/3034257