屏掉按鍵比較容易,如下:
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
// 傳回true,不響應其他key
return true;
}
屏掉HOME的方法兩種,一種是通用方法:
public void onAttachedToWindow() {
// 關鍵:在onAttachedToWindow中設定TYPE_KEYGUARD,即可屏蔽
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
super.onAttachedToWindow();
另一種是一個網友研究出來的,
WindowManager.LayoutParams lp=getWindow().getAttributes();
lp.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT; //2010,2003
getWindow().setType(lp.type);
super.onAttachedToWindow();