I need to compensate for the lack of a physical (or even a "soft") menu button on Android 3 tablets. The app I'm working on generally hides the title bar for its activities, but I can't do that if I want the action bar to appear on a tablet. Is there something in the API that I can use to determine whether a device has a menu button?
If I can't find such a function, the only thing I can think of to do is to never hide the title bar on Android 3.0 and later, but that bothers me for two reasons:
I believe Android 3.0 (or a later API) will eventually support phones, which will probably have menu buttons
I would prefer not to hard code that SDK version (perhaps I could never hide the title bar for Android 3.0 and above, but then I run the risk of not hiding the title bar on phones)
LeffelMania has the right idea, but there is a caveat: If you target SDK 11 (3.0) and use a no-title-bar theme or override with a custom title of some sort, you will be just plain menu-less, because on Honeycomb devices with the target set to 11 the options-menu lives in the title bar itself instead of a fake menu button in the bottom status bar. So be careful there! (You can work around this by setting a lower target, or targeting style resources to v11 to use a one of the Holo themes with a titlebar in that case).
DEPRECATED: This answer is no longer accurate, given changes to the Android framework and design guidelines.
Android phones are guaranteed to have a Menu button. All phones pre-Honeycomb have Menu buttons, and Honeycomb features an ever-present software button. If you use the proper callbacks that tie into the Menu button (onCreateOptionsMenu(), onOptionsItemSelected(), etc) you will be safe to receive those callbacks on any device running Android.
As of API level 14, ViewConfiguration.hasPermanentMenuKey() is available to indicate whether a permanent menu key is present.
Related
I have an action bar with many options and a menu.
On devices that don't have menu button, the overflow menu is added to my action bar.
I want to add this overflow menu button to the right of the software buttons, just like application that don't have an action bar, like this :
Is it possible, and, if it's possible, how to do this ?
Is it possible
Yes, if you do not mind your app looking like you are no longer maintaining it, thereby reducing your prospective user base.
Please read Say Goodbye to the Menu Button, particularly this passage:
However, this button doesn’t provide an ideal user experience. In fact, in apps that don’t use an options menu anyway, this action overflow button does nothing and creates user confusion. So you should update your legacy apps to remove the action overflow from the navigation bar when running on Android 3.0+ and begin using the action bar if necessary. You can do so all while remaining backward compatible with the devices your apps currently support.
Talented developers, therefore, are trying to avoid putting that affordance in the system/navigation bar, not adding that affordance.
how to do this ?
Set your android:targetSdkVersion and your android:minSdkVersion to something less than 11.
This button is automatically added by Android if your minSdkVersion and targetSdkVersion are less than API 11. 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 your targetSdkVersion and/or minimumSdkVersion are at or over API 11, then you cannot use this button.
I designed an app on the phone and am moving it to tablet. Testing on 3.2, a Samsung something-or-other. The legacy menu doesn't fill the screen using existing resources...
So, notwithstanding this, how can I make my menu fill up the horizontal space? (Besides playing tricks with wide images, if that would even work.) Again, I'm not interested (yet) in doing the action bar overflow thing.
This is not supported by the SDK. The layout of a menu is determined by the OS, occasionally modified by the device manufacturer. You, as an SDK app developer, do not have control over sizing, number of rows/columns, etc. In effect, the "menu" is an abstraction -- you simply indicate what items should be in there, and the visual representation of that is up to Android. That's why, for API Level 11+, there are zero code changes required to use an action bar, other than to have android:targetSdkVersion set to 11 or higher.
I created an app with minimum SDK 7 in order to get maximum compatibility with circulating devices. On Android phones (GB2.3), pressimng Menu button pops up a menu strip on the bottom of the screen, and that is correct.
However on HC3.2 tablets, where no menu hardware key is present, I expected a soft-menu key on the bottom of the screen, but it didn't appear, so I can't open my menu.
I don't know where to investigate and which portion of my code to share, so could you please show me where do I have to look for menu softbutton?
After reading that menus are deprecated in most recent Android versions, I don't know if ICS4 has a soft-menu button or not. I never tested my app on such a device. Can you give me advices?
Thanks
The link you provide tells you how to correctly provide action bars in your app so that the presence or otherwise of a physical menu button is irrelevant, so that's a good start.
Now, you need to combine that with a little runtime detection of the SDK version (just check the Build.VERSION.SDK_INT constant for Android 1.5 or above), along with some appropriate reflection to enable the same APK to run on any Android version starting with your minSDK version.
With the game I'm developing, I have an in-game menu the pops up when the menu button is pressed. However, I recently found out that the newer versions of Android don't have a Menu button, but instead an Action Bar.
To note, I'm not using an actual Android menu. All I'm doing is detecting that the Menu button was pressed, and then handling the event from within the game. Which means all I need is something that the user can press, and detect that it was pressed.
So my question is, how can I support both a menu button and the newer action bar? I would like my app to support API levels 7-current.
UPDATE
Okay, after reading that article, I'd like to rephrase my question. It said that it "adds the action overflow button beside the system navigation." My manifest has android:minSdkVersion="7" android:targetSdkVersion="13" but no overflow button appears on my emulator. The emulator is API 14 with skin WSVGA
This post in the Android Developers blog has a good discussion of the design transition from the old Menu Button to use of the new Action Bar and Action Overflow list.
It also includes some specific suggestions as to how to deal with your code when transitioning from pre-level 11 to the new Action Bar. May be helpful to you but for your specific application you will need to decide if you want to display an action bar or not. If not then you may want to add a button to your game interface that duplicates the functionality of the menu button on devices that have one.
Newer versions of Android do have a Menu button (see quote below). I think you best option is to just hide the Action bar, and have your game use the menu button in the same way as on older Android versions.
Quoting from Android 4.0 Compatibility Definition
7.2.3. Navigation keys
The Home, Menu and Back functions are essential to the Android navigation paradigm.
Device implementations MUST make these functions available to the user at all times when running applications.
These functions MAY be implemented via dedicated physical buttons (such as mechanical or capacitive touch buttons), or MAY be
implemented using dedicated software keys, gestures, touch panel, etc.Android 4.0 supports both implementations.
And:
Device implementation MUST present a Menu key to applications when
targetSdkVersion <= 10 and SHOULD NOT present a Menu key when the
targetSdkVersion > 10.
I am trying to get my app to be backward compatible so i need to show the menu button
since we used the menu button in our app on previous versions.
So I was reading and it says that if your target is 11 (3.0) than you don't get the menu button but it your target is 10 they you do.
But the issue is I am using fragments so my target has to be 11.
Any thoughts.
Ordinary options menus will appear regardless of Android version. If you have:
android:targetSdkVersion="11"
then the options menu will appear in the action bar on Android 3.0+ devices. All items in the options menu will be available when clicking the "overflow" button in the upper-right corner. Your options menu will appear normally on Android 1.x and 2.x devices, even if you have android:targetSdkVersion="11" in your <uses-sdk> manifest element.
If you overrode the MENU button to have other behavior, you will need to create some other trigger for that behavior for API Level 11 and higher. Overriding the MENU button was never a good idea to begin with, and as you can see, it is even less of a good idea now. I know of no way to get a MENU button on an Android 3.0 device if you have android:targetSdkVersion="11".
One thing that worked for me in order to get older Options Menu on Tablet devices was after I used the following:
minSdkVersion="11"
targetSdkVersion="10"
I think what helps over here is that I am stating to system that app has been tested against API 10 so I get older Options menu.
And because my app is meant for tablets only, keeping minSdkVersion to 11 also prevents it to be installed on the smaller devices. I know, I might still have to see the case of installation for smaller devices having ICS.