Handling the missing MENU button in new versions of Android (3.x and up)

前端 未结 6 1842
情话喂你
情话喂你 2020-12-08 12:57

I\'m a fan of the menu button as used in Android <3.0, as it was very useful for my game apps - it allowed me to take important but gameplay irrelevant functionality (sav

6条回答
  •  星月不相逢
    2020-12-08 13:41

    I added a special logic for 3.x releases. Only for these releases I use the action bar.

                if (Build.VERSION.SDK_INT == Build.VERSION_CODES.HONEYCOMB
                 || Build.VERSION.SDK_INT == Build.VERSION_CODES.HONEYCOMB_MR1
                 || Build.VERSION.SDK_INT == Build.VERSION_CODES.HONEYCOMB_MR2) {
                    requestWindowFeature(Window.FEATURE_ACTION_BAR);        
                }
                else{
    //              hide the status bar, do not use action bar         
                    requestWindowFeature(Window.FEATURE_NO_TITLE);    
                    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);               
                }
    

    For all other releases I display my own menu button and run my game in fullscreen mode. When pressing my menu button, I use the following code line, where "act" is the current activity.

    act.openOptionsMenu();
    

    As part of your menu xml, make sure to have a line like this to set "showAsAction"

    showAsAction="ifRoom"
    

提交回复
热议问题