3

I have a button with openOptionsMenu() method from Activity in it, it works fine on other Android versions, but on KitKat it does absolutely nothing... Why is that?

Psypher
  • 10,717
  • 12
  • 59
  • 83
Sartheris Stormhammer
  • 2,534
  • 8
  • 37
  • 81

1 Answers1

7

Apparently you have to override this method from Activity and write some additional code in it, so here is what I did, thanks to the comment of Luis A. Florit from this question How to open the options menu programmatically?

@Override
public void openOptionsMenu() {
    super.openOptionsMenu();
    Configuration config = getResources().getConfiguration();
    if ((config.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) > Configuration.SCREENLAYOUT_SIZE_LARGE) {
        int originalScreenLayout = config.screenLayout;
        config.screenLayout = Configuration.SCREENLAYOUT_SIZE_LARGE;
        super.openOptionsMenu();
        config.screenLayout = originalScreenLayout;
    } else {
        super.openOptionsMenu();
    }
}
Community
  • 1
  • 1
Sartheris Stormhammer
  • 2,534
  • 8
  • 37
  • 81
  • I had a similar problem with the Nexus 10 API 27 emulator. It worked in the other emulators. This solved my problem. Thank you for sharing. – RickC Jun 03 '18 at 00:51