سؤال

I am just making some tests and I created a simple immersion menu in a hello world activity. To do that, like it is said here, I had to implement the method onKeyDown:

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
        openOptionsMenu();
        return true;
    }
    return false;
}

The menu is shown properly but the problem is that now the one-finger-down gesture to just close the app doesn't work and for any reason I had to make a two-finger-down gesture to close it. Why is it happening?

هل كانت مفيدة؟

المحلول

Your problem is that you override the onKeyDown function.

You have two solution :

  • Handle yourself the KEYCODE_BACK like that :

    if(keyCode == KeyEvent.KEYCODE_BACK){ onBackPressed(); return true; }

  • return super.onKeyDown(keyCode, event); instead of return false;

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top