Show options menu button on Galaxy Nexus (Android 4.1)

Sharanabasu Angadi picture Sharanabasu Angadi · Mar 6, 2013 · Viewed 12.8k times · Source

I am using options menu in my app. But when I install the app on a Galaxy Nexus, I don't see options menu because by default it doesn't have options menu button. How can I show options menu button in my App for only Galaxy Nexus? With other phones it's fine, and I can get options Menu.

Answer

Michael Celey picture Michael Celey · Mar 6, 2013

In Android 3.0, Google switched from having a dedicated menu key to using the ActionBar for menu functionality. If your build target is 3.0 or above, your menu will default to using the ActionBar.

If there is a menu key on the phone, any run over options that are usually shown by the three dots icon in the action bar will instead show up with the menu button. If there is no menu key on the phone, all options will be shown on the action bar. Because the menu key is going away, it is encouraged that you utilize the ActionBar class for your menus from 3.0 and beyond.

Now, older apps that run on new platforms without a menu key will generate a fake menu key next to the recent apps button. This makeshift menu key will only appear if your build target is 2.3.4 or below since it's only there for backwards compatibility reasons. (edit: build target should be anything less than, or including API 13)

In your case, you should utilize the ActionBar for your menu since you're building against a newer version of Android. If you're worried about backwards compatibility then you can always utilize a library such as ActionBarSherlock to use the action bar on older platforms.