android 禁用home键

1.只屏蔽Home键,只需在Activity中重写onAttachedToWindow()方法
         public static final int FLAG_HOMEKEY_DISPATCHED = 0x80000000;
    @Override
    public void onAttachedToWindow() {
        //关键:在onAttachedToWindow中设置FLAG_HOMEKEY_DISPATCHED
        this.getWindow().addFlags(FLAG_HOMEKEY_DISPATCHED);
        super.onAttachedToWindow();
    }
2.只屏蔽返回键,只需在Activity中重写onBackPressed()方法
     public void onBackPressed() {
    //        super.onBackPressed();
     }

你可能感兴趣的:(android,禁用home键)