Menu button on newer android devices - android

I'm creating an Android app for version 2.3.3 and higher (using the same SDK version) and I have used a legacy menu button.
I also have used a custom ActionBar library that doesn't have the menu overflow (?) capability. So is there any way for me to display the menu on newer Android devices without the physical menu button? Preferably without having to change the ActionBar to use another library or without having to use Android's newer SDKs?
Thanks.

and I have implemented a legacy menu button
What for? Android would handle this by itself if your application is legacy one, it will add on-screen menu button on Honeycomb and up, so you just do not need to bother.
See this article: Say goodbye to menu button
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
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.
Soft menu key for legacy app would look like this:

You might also check a couple of my answers from the past few days. Both the questions are for ActionBarSherlock
Answer 1
Answer 2
NOTE: As also mentioned in both these answers, and I would like to reiterate. This is merely putting an option across for devs who would still like to force the OverFlow menu.

Related

Text button text all caps for older api 8

I am using android studio 2.1.2 and I need to design a app for api level 8 (android froyo). But I come up with 2 problem one is if I choose blank activity then is shows the rendering issue and second one is all the button text is appearing on capital letter. After some time on google I found that android:textAllCaps="false" but the issue is the property is not supported by the Api level 8 it requires minimum level 14. It will be very helpful if some one can able to solve this. I suppose that is is a matter of theme but most of the theme is not supported by lower api, I use different theme also but the problem remains, if any one knows a specific theme which don't force to make all the text to be caps.
try this in your Activity
mButton.setTransformationMethod(null);

Android, knowing which api level to target

Using http://developer.android.com/about/dashboards/index.html I can see that going as far down as Gingerbread/API Level 10 all the way up will give me a range of 99.6%, but I am fairly new to Android development, I have never released an application and have some questions:
In my gradle script I have minSdkVersion as 10, targetSdkVersion as 21, is that right?
In my manifest file for all activities except my starting activity, I have the parentActivityName set. This gives a warning saying parentActivityName is only used from API Level 16, even though I use meta-data with parent activity defined in there. Am I missing something?
If I keep my manifest "as-is" and launch, will users running pre level 16 run into errors navigating back up the activity hierarchy?
Finally I tested my application in an emulator set to API Level 10 and there was no issues except for some minor UI stuff, however there was no way that I could see to press "Back" so I had to end the activity via Android Studio. How do you emulate going back in Gingerbread 2.3? My app does not have an action bar with left caret. Solely uses the phone's back button.
(1) Yes, you should always target the latest API. Source here.
(2) You don't need to specify your parentActivityName in the manifest. To get rid of the warning, you might as well remove the attribute. Source here.
(3) Not if you have set your minSdkVersion to 10, and implemented functionality that corresponds to these API levels. Also, when publishing to Google Market, devices that do not meet up with the minSdkVersion will not be able to download your app.
(4) Android phones always comes with a hardware back button. There is no need for the developer to implement this behavior, except when you want to modify it for your own needs. Source here.

Using ActionBarSherlock Menus shows old menu button on new 4.0 and higher - Picture Included

I've been looking for a while and I just want to know whether or not I'm wating my time trying to get rid of the little menu icon that show's up in my app to support older applications that don't have the ActionBar implemented.
How do I get rid of it (as a bonus: does it have an actual name)?
First the bonus: it's called the legacy overflow button.
The correct way to get 'rid' of it on devices that do not implement a dedicated menu button, is to set either minSdkVersion or targetSdkVersion to 11 or higher. In that case, the system will not add the legacy overflow button.
There is a small exception though: if you do not use the ActionBar, set minSdkVersion to 10 or lower and set targetSdkVersion to 11, 12, or 13, Android will add the legacy overflow button when running your app on a handset with Android 4.0 or higher.
You can read all the details in this blog post on the Android dev website.
Set your targetSdkVersion to 14 or higher.

How to implement the action bar for Android version 4.0?

I implemented an app that works from 2.1 and on. But my app has the menu functionality to exit from the app. I installed the app in an Ice Cream Sandwich (ICS, version 4.0) device and it's working fine. But ICS doesn't have menu buttons - instead of this it has the action bar. I am new to this concept. I want to integrate this into my app. I tried but I am not succeeding.
For this I follow these steps:
android:targetSdkVersion="11" in the Android manifest.
android:showAsAction="ifRoom|withText" --> add to menu.xml (which is in the menu folder) but I get the following error:
No resource identifier found for attribute 'showAsAction' in package 'android'
You should start with a working Options Menu implementation. Test it on a 1.x or 2.x emulator to make sure it works. Then set your targetSdkVersion to >=11 (if it isn't already) and verify the menu appears in the ActionBar on >= 3.0. Only devices or emulators running Android 3.0 or above will draw an Action Bar. Older versions still use the Options menu. Once the menu appears in the ActionBar, you can start adding the showAsAction attribute to individual items in the menu XML.
To set targetSdkVersion:
Open up your Project properties, select Android, and select an Android SDK to link your project against. For both the Project properties and your Android Manifest targetSdkVersion, I recommend using the newest SDK available.
minSdkVersion defines the lowest version of Android the app will run on. targetSdkVersion defines the highest version of Android the app knows about when built -- which classes and methods are available, what constants are defined, etc. It may run on newer versions, but it won't know about any features added after targetSdkVersion.
More information about API Level.
If you want an ActionBar to display on Android <3.0, make a project based on Action Bar Sherlock or the Action Bar Compatibility sample from the SDK. But don't try this until you are comfortable with your ActionBar in >= 3.0.
you may find a good Example code over here.

Android menu and action bar conversion

There is a new concept in Android:
http://android-developers.blogspot.com/2012/01/say-goodbye-to-menu-button.html
But it isn't clear fro me. I have an application which is support from 1.6 to 4.0. And I want to follow the new concept, but I can't set showAsAction property in the menu xml because:
"No resource identifier found for attribute 'showAsAction' in package 'android'"
It's normal because there is in the doc:
"Note: The android:showAsAction attribute is available only on Android 3.0 (API Level 11) and greater."
How can I set the menu, that under 3.0 is a simple menu but over 3.0 as an ActionBar?
Per the blog post that you shared:
Summary
Android no longer requires a dedicated Menu button, some devices don’t have one, and you should migrate away from using it.
Set targetSdkVersion to 14, then test your app on Android 4.0.
Add showAsAction="ifRoom" to menu items you’d like to surface in the action bar.
If the ActionBar doesn’t work for your app, you can remove it with Theme.Holo.NoActionBar or Theme.DeviceDefault.NoActionBar.
So, all you really have to do is this:
First, set your SDK min and target version in the AndroidManifest.xml file like this:
<uses-sdk
android:minSdkVersion="4"
android:targetSdkVersion="14" />
Second, add showAsAction="ifRoom" to the menu items in your menu.xml file.
Now run your app in Honeycomb or Ice Cream Sandwich and you should see your menu in the action bar. Your app should still work for the pre Android 3.0 releases.
Go to project properties in Eclipse (right-click on project and select Properties),
then go to Android section, and change Project Build Target to Android 4.0. This must be done so that the build system recognizes showAsAction.
Don't worry that your project won't be runnable on Android less than 4.0, you can still run it as long as you don't call a class or method available only on 4.0.
You can use Build.VERSION to do something different in every versions。
Some like Build.VERSION.SDK_INT<Build.VERSION_CODES.HONEYCOMB
You can use some os technology to provide actionbar in apps with API level less then 11.
Consider using ActionBarSherlock. You can just add it as library project to your project and if you won't set the Sherlock theme it won't show action bar(in case you don't want to show it), yet you can mark your menuitems with "showAsAction". On devices with API level higher than 10, action bar with your menuitems will be normally shown.

Categories

Resources