//重写
public voidonAttachedToWindow ( ) {this . getWindow ( ) . setType ( WindowManager. LayoutParams . TYPE_KEYGUARD ) ;
super . onAttachedToWindow ( ) ;
}
以上方法只针对2.3系统有效,但是在4.0后就没有效果了,要实现如下publicstaticfinalintFLAG_HOMEKEY_DISPATCHED=0x80000000;//定义屏蔽参数<uses-permissionandroid:name="android.permission.DISABLE_KEYGUARD"/>//权限
this.getWindow().setFlags(FLAG_HOMEKEY_DISPATCHED,FLAG_HOMEKEY_DISPATCHED);//onCreate中实现
// 屏蔽返回键、菜单键、home键、音量键
@Override public boolean onKeyDown(int keyCode, KeyEvent event) {// TODO Auto-generated method stub switch(keyCode){case KeyEvent.KEYCODE_BACK: case KeyEvent.KEYCODE_HOME: case KeyEvent.KEYCODE_MENU: case KeyEvent.KEYCODE_VOLUME_DOWN: case KeyEvent.KEYCODE_VOLUME_UP: case KeyEvent.KEYCODE_VOLUME_MUTE:return true; default: return false }}
如果觉得《Android 屏蔽返回键 菜单键和Home键》对你有帮助,请点赞、收藏,并留下你的观点哦!