Android Menu option not appearing in Android 4.4

前端 未结 2 1593
一个人的身影
一个人的身影 2021-01-28 23:18

I have a options menu in my application which I have tested to work on Android 4.0. The code is as shown below:

@Override
    public boolean onCreateOptionsMenu(         


        
相关标签:
2条回答
  • 2021-01-29 00:02

    Put this inside your activity class if you want to Force to the Application to show the Action Overflow:

        try {
            ViewConfiguration config = ViewConfiguration.get(this);
            Field menuKeyField = ViewConfiguration.class
                    .getDeclaredField("sHasPermanentMenuKey");
            if (menuKeyField != null) {
                menuKeyField.setAccessible(true);
                menuKeyField.setBoolean(config, false);
            }
        } catch (Exception ex) {
            // Ignore
        }
    

    Read This http://developer.android.com/design/patterns/compatibility.html

    The action overflow in the action bar provides access to your app's less frequently used actions. The overflow icon only appears on phones that have no menu hardware keys. Phones with menu keys display the action overflow when the user presses the key.

    0 讨论(0)
  • 2021-01-29 00:14

    Good practice is to call through to the super class:

    @Override
    public boolean onCreateOptionsMenu(Menu menu)
    {
        MenuInflater menuInflater = getMenuInflater();
        menuInflater.inflate(R.layout.menu, menu);
        return super.onCreateOptionsMenu(menu);
    }
    

    The reason you're not seeing the menu is probably that the device has a hardware menu button and that must be pressed to show the options menu.

    Are you using the emulator? What is the setup for that?

    0 讨论(0)
提交回复
热议问题