Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show options menu button on Galaxy Nexus (Android 4.1)

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.

like image 215
Sharanabasu Angadi Avatar asked Mar 06 '13 14:03

Sharanabasu Angadi


2 Answers

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.

like image 73
Michael Celey Avatar answered Nov 03 '22 01:11

Michael Celey


You need to think about why you want an "options" button - this is an old, poor pattern, which has been superceded by the ActionBar which really is much nicer.

But you might need it, for client reasons (like I needed to keep it in for the client). If that's the case, then you can follow my advice below (slightly edited from original that mistakely mentioned "action bar")


You can set your build target to a version before ICS (i.e. up to and including API 13 / HoneyComb 3.2).

<uses-sdk
    android:minSdkVersion="7"
    android:targetSdkVersion="13" />

That will get the system to use a compatibility mode setting that inserts an overflow icon into your phone's bottom button bar - this should provide the functionality you are after. Pressing this button will have the same response as pressing a "menu" button on the Samsung Galaxy S2 for example.


Here you can see the compatibility "options" button, and the menu that has been shown when it was pressed:

ICS compatibility options button on Galaxy Nexus


Note:

As other commentators mention, you should consider the better choice of the ActionBar pattern. If you want backwards compatibility, then I recommend the Action Bar Sherlock library.

But if you are looking for a quick fix, or the client can't afford a big refactor to move to the Action Bar pattern, then this is the way to do it.

like image 39
Richard Le Mesurier Avatar answered Nov 02 '22 23:11

Richard Le Mesurier