openOptionsMenu function not working in ICS?

后端 未结 8 2018
一整个雨季
一整个雨季 2020-12-03 21:07

Im using action bar compability library. Im trying to open the options menu from a button with openOptionsMenu() function but it does nothing.

Menu shows as usual wh

8条回答
  •  鱼传尺愫
    2020-12-03 21:54

    I was having the same problem trying to go around this openOptionsMenu thing on an app that I was doing that should run on Android 1.6 and up. Following the answer from Werner Van Belle I reached the conclusion that we could achieve a workaround to solve the problem. So I came up with the following code, it's always beatiful when people don't mark a method as final, so we can always override it. It's perfect if you don't want to give up on targeting your app to the latest api (android:targetSdkVersion="17"). I hope you guys like it. :)

    @Override
    public void 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();
        }
    }
    

提交回复
热议问题