android 屏蔽Home键, 屏蔽BACK键,MENU键(亲自实践有效)

1.屏蔽Home键
@Override
public void onAttachedToWindow() {
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
super.onAttachedToWindow();
}



2、拦截/屏蔽返回键、MENU键实现代码
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if(keyCode == KeyEvent.KEYCODE_BACK) { //监控/拦截/屏蔽返回键
        return true;
    } else if(keyCode == KeyEvent.KEYCODE_MENU) {//MENU键
        //监控/拦截菜单键
         return true;
    }    
return super.onKeyDown(keyCode, event);
}

你可能感兴趣的:(android 屏蔽Home键, 屏蔽BACK键,MENU键(亲自实践有效))