android 禁用back键的方法

1.保证拦截(可能会造成其他按键失效)

    @Override
    public boolean dispatchKeyEvent(KeyEvent event) {
    
    
        switch(event.getKeyCode())
        {
    
    
            case KeyEvent.KEYCODE_BACK:
                return false;
        }
        return true;

2.相关事件禁用

@Override
    public void onBackPressed() {
    
    
        //super.onBackPressed();
    }

猜你喜欢

转载自blog.csdn.net/weixin_46139477/article/details/125386950