0

I am having trouble inflating an options menu from xml. Here is my code:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // TODO Auto-generated method stub
    super.onCreateOptionsMenu(menu);

    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu, menu);
    return true;
} 

It runs fine when I press the menu button on the emulator but there is no menu bar when I run it on an actual device running ics.

Denizen
  • 335
  • 5
  • 17

1 Answers1

0

The menu-button was removed from devices which run Android 3.0 and higher and is now considered "deprecated". There is a nice Blog-post about why, how to use the new ActionBar and how to keep legacy support for older applications:

If your app runs on a device without a dedicated Menu button, the system decides whether to add the action overflow to the navigation bar based on which API levels you declare to support in the <uses-sdk> manifest element. The logic boils down to:

  • If you set either minSdkVersion or targetSdkVersion to 11 or higher, the system will not add the legacy overflow button.
  • Otherwise, the system will add the legacy overflow button when running on Android 3.0 or higher.
  • The only exception is that if you set minSdkVersion to 10 or lower, set targetSdkVersion to 11, 12, or 13, and you do not use ActionBar, the system will add the legacy overflow button when running your app on a handset with Android 4.0 or higher.

If you're starting Android development or you're creating a new application now, don't use this kind of menu but rather use the ActionBar.

Helpers are available in the "Support Library" for backwards-compatibility:

The ActionBar is not supported by the library. However, when creating your Options Menu, you can declare which items should be added to the Action Bar when it's available (on Android 3.0 or later).

Lukas Knuth
  • 25,449
  • 15
  • 83
  • 111