calling menu from custom button in jelly bean - android

I would like to call my menu from a custom button :
With targetversion<=10 this works fine with calling openOptionsMenu from onClick-Method of the button:
openOptionsMenu();
From targetversion>=11 this doesn't work.
Also to mention. With <=10 the Menuitem appears at the bottom:
With >=11 this icon disappeared.
Background :
I like to have a targetversion=16.
My app hides the TitleBar and Optionmenu appears in the Titlebar in Jelly Bean.
Because of this I want to get rid of the google UI's changes every release, which costs a lot of developing/testing efforts every time. So I thought to have my own button which is GoogleApi independent.
Does anyone have any ideas or suggestions ?
regards

Are you sure you are calling openOptionsMenu() from an Activity? SDK documentation still mentions it as an active API. I double checked with <uses-sdk android:minSdkVersion="1" android:targetSdkVersion="17" /> and works just perfect.

Related

Remove Android options menu in XE5 Delphi

Is there a way to completely remove the Android options menu in XE5 Delphi? I've been testing my application on a HTC One and because my phone doesn't have a menu button and my application doesn't have an options button, android automatically adds a options menu. Since this button is added by Android there is no way to add items to the menu.
I've already tried to change the minimal SDK version, but this makes the application very unstable and makes it crash when the orientation is changed:
<uses-sdk android:minSdkVersion="14" />
Is there an other way to remove the options menu? Now there is just a large options menu in the bottom of my screen that has no menu items.
Ok, you're right in that this empty action overflow menu is added because of your lack of hardware menu button.
On a Nexus 7 it's not such an issue as the empty overflow menu is added at the end of the other soft buttons.
On a HTC One, however, you can configure the Home button to act as a menu button, which removes the action overflow button.
It's not correct to say you can't add items to the menu. My Android session at CodeRage 8 shows how to add menu items. However, I'll grant you, it's a bit of a faff.
In order to remove it, the docs say you should set the targetSdkVersion attribute (not minSdkVersion) in your Android manifest to 14 (see this blog post for details). However having tried this it causes a crash if you don't prevent rotation in the RTM version of XE5, as you saw with your tests. This issue is sat in QC, logged some weeks back, hopefully to receive a fix in the near future.
However you should consider restricting the rotation as one course of action...... This is easy enough.
you must change in manifest android:configChanges="orientation|keyboardHidden">
to:
android:configChanges="orientation|keyboardHidden|screenSize">
then you can set minsdk, maxsdk, targetsdk as you want, and application will not crash

action bar behavior when android:targetSdkVersion is 16

I am trying to implement an action bar with tabs as navigation options. To do that I select the "Tabs+Swipe" option in the "New Blank Activity" section of the "New Android App" wizard as shown below.
Now, in the android manifest, when
android:targetSdkVersion="15"
which is the default value, the action bar looks like this on a Nexus 7/Nexus 7 emulator, this is the desired look of the app
Now when I change that line in the android manifest to
android:targetSdkVersion="16"
the look of the action bar changes to this
The default look remains for any version of android but 16, can anyone please explain why the look of the action bar suddenly changes when the targetSdkVersion is set to 16?
The above is reproducible in the emulator as as well as on a real nexus 7.
Full screengrabs for
Normal: http://i.stack.imgur.com/VsBA2.png
After android:targetSdkVersion="16": http://i.stack.imgur.com/OM6Y4.png
Update-10th March, 2013: Switched to the List Navigation mode (instead of Tabs) to enable move to android:targetSdkVersion=17
The reason it changes when setting targetSDK to 16 is because Google changed how tabs are measured in Jelly Bean. Specifically, look at this in android.internal.view.ActionBarPolicy:
public boolean hasEmbeddedTabs() {
final int targetSdk = mContext.getApplicationInfo().targetSdkVersion;
if (targetSdk >= Build.VERSION_CODES.JELLY_BEAN) {
return mContext.getResources().getBoolean(R.bool.action_bar_embed_tabs);
}
// The embedded tabs policy changed in Jellybean; give older apps the old policy
// so they get what they expect.
return mContext.getResources().getBoolean(R.bool.action_bar_embed_tabs_pre_jb);
}
However, I suspect you don't just want the reason, but a solution. Unfortunately, I can't give you a straightforward way to set it to only embedded.
I can suggest using ActionBarSherlock to make it consistent, though. The bonus to that is the ability to use actionbars on older devices. When using it(portrait), I can confirm that if you set the targetSDK to 16, it uses the stacked layout on Jelly Bean, Ice Cream Sandwich, GingerBread, and Froyo. At least you will be able to design your layout while knowing what to expect.
Keep in mind that in most cases, switching to landscape mode will embed them in the actionbar again, since there is "enough room" the way it measures.

Android - No hardware menubutton

I concluded the newer android tablets doesn't have a hardware Menubutton anymore.
So I was wondering if I have to insert an menu button in my own (fullscreen) app or does android offer a software included menubutton itself (even when my app runs fullscreen)?
(I don't have an android phone/tab myself to test, so I asked here)
Thanks,
Dennis
You should move away from menu buttons. It's the new style of Android applications. See this post from Android developer with the reasons to remove the button and what applications should do instead of offering a menu button.
Most of devices which are not having menu hardware button runs on android 3.0 or greater version
You just need to add one parameter as showAsAction.
Which will show menu item on action bar.
Concider reading ActionBar tutorial
Change the manifest file: you should change targetSdkVersion to <= 10.
Like this:
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="9"/>

how do I update the Android options menu so the backward compatible actionbar updates?

I have made a android app with the "new" actionbar and fragments api but I wanted it to work on phones below android 3.0... so I tested this one:
http://developer.android.com/resources/samples/ActionBarCompat/index.html
and using the compatibility pack from google...
but I now realize that the setHasOptionsMenu(true) wont work...
to sum it up, I want to update the actionbar menu from runtime... I have tried updating the options menu but havent found a way that works... so please help me :)
Edit: One thing I have realized is that it isnt the setHasOptionsMenu(true) function that wont work, its the actionbar that doesnt update when I try to update the optionsmenu...

android button widget with a dropdown list, what is the name of this particular widget?

Im learning android layouts and Ive noticed a particular button widget in some android apps that I would like to add to my own apps, Im just not entirely sure what its called, In some cases this button widget even will include a dropdown list here are a few examples of what Im talking about.
in the first image you will notice that the checkmark, the camera and the pencil are all sitting inside of the button widget i'm after, and in the youtube app you will notice the thumbs up, thumbs down and more buttons
That's ActionBar. Native support for 3.0+ devices, and some work to do in pre 3.0-devices. You can find example in new api 14 samples(called "ActionBarCompat").
Please see my answer here which gives some good links on how to implement the "dashboard" pattern, and use the "quickaction" bar. I think this should put you on the right path. Also there is a link on how to implement the "action bar."
EDIT: According to Mighter, if you use API 1.6 - 2.3 there should be official Google samples for this now. Please see this.

Categories

Resources