I know, this sounds dumb, but bear with me.
I use the following
android:minSdkVersion="8"
android:targetSdkVersion="17"
android:Theme.Holo"
When I run my app on 2.2 emulator, the menu button brings up my menu.
Whhen I run my app on 4.2 emulator, should the action bar not automatically be activated? I can see program icon + title. I have added some menu items like this:
<item android:id="#+id/itemShare" android:title="#string/titleShare"
android:icon="#android:drawable/ic_menu_share"
android:showAsAction="ifRoom"></item>
I then have defined
onCreateOptionsMenu
all my activies inherit from.
Yet, I see nothing "action bar" icons when running my app in 4.2 emulator. I must be missing something obvious.
I am very new to Android and Eclipse, but I am slightly confused of above. The way I do it, should that not be the way to get pre/post honeycomb compability assuming one does not want to use ActionbarSherlock?
Whhen I run my app on 4.2 emulator, should the action bar not automatically be activated?
Yes.
I can see program icon + title.
That is the action bar.
Yet, I see nothing "action bar" icons when running my app in 4.2 emulator. I must be missing something obvious.
Your emulator has decided that there is insufficient room to show the icons, so they are in the overflow. Depending on your emulator configuration, you activate the overflow by pressing the MENU button or by pressing the ... affordance in the action bar on the right.
The way I do it, should that not be the way to get pre/post honeycomb compability assuming one does not want to use ActionbarSherlock?
Yes.
Related
When in some apps, there are those 3 dots in the top right of the app, on the action bar (not the home buttons), which allow for more options. In my app I have on, but I do not know how to make it do a method when it is clicked. Do I use android:onClick="METHOD_NAME ? Or do I need to setup a button variable in my activity class and setup and onClickListener? I have already tried both but I may be doing something wrong.
That three dots are the menu in the action bar. They are always shown on devices without a menu key.
See also the documentation for more details.
Three dots are called Overflow(very aptly named) and to use them you need to use ActionBar which is the top long, horizontal bar showing icons, other buttons along with the Overflow button.
Now in some devices where there is no physical menu button you will always see Overflow button.
Go through Docs and tutorials related to ActionBar but keep one thing in mind that ActionBar is only available for devices with android above HoneyComb. For android devices below 3.0 such as GingerBread or Froyo you will have to use compatibility libraries, so that will be an additional task.
And most notable libraries for this purpose are ActionBarSherlock and AppCompat.
From the article "Say Goodbye to the Menu Button "
it seems now the menu button is going to the action bar.
"If you’ve already developed an app to support Android 2.3 and lower,
then you might have noticed that when it runs on a device without a
hardware Menu button (such as a Honeycomb tablet or Galaxy Nexus), the
system adds the action overflow button beside the system navigation. "
But since I do not want the action bar takes the space, and I only need one menu button there, I hope I had a menu button within the navigation bar at the bottom.
How to do that?
[Update] From one aplication's code, it seems if I set the target level is lower, and use the add menu function, the menu button can be put with the navigation bar at the bottom. But anyway, as Samus Arin said, if there is only button for the menu, it doesn't make sense to build a action bar.
You can develop for newer releases, and then detect if there is a menu-button on the device. If there is not, show your own in the UI.
http://developer.android.com/reference/android/view/ViewConfiguration.html#hasPermanentMenuKey()
Ex.
if(ViewConfiguration.hasPermanentMenuKey(context)){ Has menu-button } else { Does not have menu-button, show in UI }
As you said, if you want the overflow-button in the navigation-bar you have to set the target-sdk to 13 or lower.
IMO this option should be given to the developer regardless of targetsdk.
UPDATE: hasPermanentMenuKey() can only be used in SDK>13, so you have to check this manually in your code.
until now I compiled my app with SDK for Android 2.1. There the options/preferences button appeared automatically, I only had to bring it alive by providing methods onPrepareOptionsMenu() and onMenuItemSelected().
Now i switched over to SDK for 2.2 and my whole layout is...hm...damaged. Most obvious problem: the options-button is gone.
So what do I have to do to re-enable it for 2.2?
Thanks!
There the options/preferences button appeared automatically
There has never been an "options/preferences button" in Android that "appeared automatically". I am going to guess that you mean the legacy menu affordance in the system bar/navigation bar on Android 3.0 devices, for apps with android:minSdkVersion set too low.
So what do I have to do to re-enable it for 2.2?
The legacy menu affordance has nothing to do with your build target. It has everything to do with your android:minSdkVersion. More importantly, your objective should be to get rid of this affordance, as it is a sign to users that your app is out of date.
If you are using onPrepareOptionsMenu(), you should be using the action bar, in which case your former menu items will either appear in the action bar directly as toolbar-style buttons, or in the action bar's overflow menu ("..." button), or via a popup menu that appears when the user presses their device's MENU button.
If you do not want the action bar, then do not use onPrepareOptionsMenu(). Instead, create your own menu structure using your own widgets as part of your own activity UI.
You can read more about the action bar and the vanishing menu affordance in the documentation.
I have a non-market app that was built to run on a specific device. Originally, this was on a device running 2.2, but now the app is targeting a specific device on 3.1 and I am adding in support for the Action Bar.
One of the apps Activities is required to be full-screen and have hidden the status bar and the Action Bar. This is achieved using the following in the manifest:
<activity
android:name=".activity.EditorActivity"
android:label="#string/activity_edit"
android:theme="#style/Canvas">
Which references this style:
<style name="Canvas" parent="#android:style/Theme.NoTitleBar.Fullscreen">
<item name="android:windowBackground">#color/bg_white</item>
</style>
So, after moving to 3.1, the effect works, in that the Activity is fullscreen, and everything is hidden as needed, but this of course hides the options menu from populating the Action Bar.
I know that if I leave the android:targetSdkVersion="8", the options menu is shown in the bottom navigation, but this seems like a bit of a hack - is there any other way or 'best practice' for this? I basically have to set android:targetSdkVersion="12" to ensure the app works and isn't put onto older devices so this won't be a permanent solution.
I've decided to stop trying to swim upstream and have switched to using a translucent Action Bar that is overlaid - it works perfectly and is exactly what I had been doing prior to 3.x with my custom solution.
Custom Translucent Android ActionBar
I'm On Honeycomb (3.1) and my first problem is that I don't know what is the name of the bar at the bottom of the OS (appears in every application). I've seen some apps add options to this bottom bar (it has by default the back button the home button and the show active programs button, besides the watch, battery indicator and signal connection strength). When a certain program uses options it sometimes adds them to this bottom bar (it is usually seen as a grid-like icon next to the show active programs buttons, which you can click and a menu pops up.
I've described it as best as I can, but My question is simple: how can I create a menu like this on in my app?
Thanks for any help!
EDIT:
Ok, I've just read it's a compatibility feature. And it's not supposed to be there in an Android App.
I feel stupid...
I'm On Honeycomb (3.1) and my first problem is that I don't know what is the name of the bar at the bottom of the OS (appears in every application).
That is the "system bar".
I've seen some apps add options to this bottom bar
This happens automatically for applications that set up an options menu using onCreateOptionsMenu(). However, once the application switches to the Honeycomb look-and-feel (e.g., via android:targetSdkVersion="11"), the options menu moves to the action bar.
how can I create a menu like this on in my app?
Long-term, you do not want to do this, because it means that you will not have the action bar and will not look like you belong on Honeycomb, Ice Cream Sandwich, etc.
Short-term, simply do not have android:targetSdkVersion="11", and implement an options menu as normal.