Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android openOptionsMenu does nothing in KitKat

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?

like image 740
Sartheris Stormhammer Avatar asked Apr 24 '26 18:04

Sartheris Stormhammer


1 Answers

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();
    }
}
like image 127
Sartheris Stormhammer Avatar answered Apr 27 '26 07:04

Sartheris Stormhammer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!