Disable home button in android

2020-05-08 06:13发布

I add this code in my activity

public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_HOME) {
            return false;
        }
        return super.onKeyDown(keyCode, event);
    }

public void onAttachedToWindow() {
    super.onAttachedToWindow();
    this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
}

and the home button is looks like it is disabled

But the problem is when someone press the menu button and when my menu button is shown and the user press home button then the home button is enabled and home screen is shown

1条回答
Animai°情兽
2楼-- · 2020-05-08 06:41

You should absolutely not be disabling the home button in an Android application. This is a major anti-pattern, and will both make your app labelled as spammy and malware-like. Users hate when you disable their home button, and you should really avoid it at all costs. (At the very least, it will get you poor market ratings.)

查看更多
登录 后发表回答