Android禁用返回键

Android禁用返回键

只需要重写dispatchKeyEvent方法就可以了。

@Override
    public boolean dispatchKeyEvent(KeyEvent event) {
        if(event.getKeyCode() == KeyEvent.KEYCODE_BACK ) {
            //do something.
            return true;
        }else {
            return super.dispatchKeyEvent(event);
        }
    }

相比于onBackPressed和onKeyDown方法有时候没有效果,这个方法能保证禁用手机的返回键。

猜你喜欢

转载自blog.csdn.net/qq929371489/article/details/80519218
今日推荐