在activity里面重写onAttachedToWindow方法,就可以了,经本人测试onKeyDown事件这里都不用判断了。
@Override
public void onAttachedToWindow() {
getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
super.onAttachedToWindow();
}
可有可无onKeyDown
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if(keyCode == KeyEvent.KEYCODE_MENU)
{
onCreateDialog(keyCode);
}
if (keyCode == KeyEvent.KEYCODE_BACK)
{}
if(keyCode == KeyEvent.KEYCODE_HOME)
{}
return false;
}