Neil Walker
Neil Walker

Reputation: 6848

How action bar on devices with menu button functions

Essentially I'm confused over when and how the options menu is shown with devices with and without menu buttons on Android devices 3.0 and above.

Focusing specifically on options menu, I know from reading that the options menu is inflated in onCreateOptionsMenu (whether via menu button or action bar) and the Google developer site states that 'items in your options menu appear on the screen depends on the version for which you've developed', i.e. bottom menu or action bar.

I've tried a few apps (e.g. gmail) on a Nexus 4 and Samsung phone, both with Jelly Bean. The Nexus has no menu button and gmail displays the options menu in an action bar. On the Samsung there is a menu button and there is no action bar, you have to press menu.

Is the options menu handled automatically by Android or is there some code going on within the app to determine if a menu button is present?

Also, what further confused me (i.e. contradicted this thought) is the Android developer site says if you use Theme.Holo you get an action bar, which kind of tells me it's not implicit how the action bar is displayed.

Thanks for any guidance.

Upvotes: 1

Views: 465

Answers (2)

Onur A.
Onur A.

Reputation: 3017

Normally beginning with Android 4.0 the menu options embed into ActionBar and menu button is removed, but it's not necessary just optional and you have to handle it in your code to show to user For the menu button on Samsung I guess it is only in the Samsung models, since if you can look at the new models of other device manufacturers, there is no menu button at all. Samsung takes the options button in the action bar to the menu button(harware button).

Upvotes: 0

Stevie754
Stevie754

Reputation: 124

If you want to check if a device has softkeys use hasPermanentMenuKey using

boolean hasMenuKey = ViewConfiguration.get(context).hasPermanentMenuKey();

If that returns true it means you don't have the soft keys.

If guessing most android applications have some sort of built in functionality to do a similar check and determine whether a menu is needed or not.

Upvotes: 1

Related Questions