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
Related
I'm a new to Android development and I've been giving Android Studio a spin. I've followed Google's tutorial and I still haven't been able to get the ActionBar up and running either on the emulator or on the real device. I've specified the min version in the manifest file and I've also edited the menu and activity xml files accordingly.
Confusingly, the UIs shown in the activity_foo.xml and menu_foo.xml are different:
activity_foo.xml:
menu_foo.xml:
Even more confusingly, the final app when built shows both the Search and Settings in the hamburger menu though I do not recall seeing it in the GUI previews:
How can I fix this?
Confusingly, the UIs shown in the activity_foo.xml and menu_foo.xml are different
They are supposed to be different. One is showing you a layout file. The other is showing you a menu resource. Their previews are not supposed to necessarily match. After all, an Android app that is bigger than a breadbox will have many layout resources, few of which will be defining the contents of an activity.
For those layouts that do define the contents of an activity, IIRC, you can have the same tools:context=".FooActivity" in the root element of your layout file, and the preview may take that into account.
Even more confusingly, the final app when built shows both the Search and Settings in the hamburger menu though I do not recall seeing it in the GUI previews:
In the preview, the search item is represented by a toolbar-style button (icon is a magnifying glass).
In your menu resource, you have one <item> that has android:showAsAction and one <item> that has app:showAsAction. Either you are using the appcompat-v7 action bar backport, or you are not. That would be determined by things like:
what Java class your activity inherits from (ActionBarActivity or AppCompatActivity for appcompat-v7)
what theme you are using for the activity in your manifest (if it is based on Theme.AppCompat.*, you are using appcompat-v7)
If you are using appcompat-v7, you need to change the android:showAsAction to app:showAsAction. Given the results of your run of the project in the emulator, my guess is that you are using appcompat-v7. If you make the change to the menu resource and run the project again, you may see the search item show up as the magnifying glass icon, as you see in the preview. I say "may" because there may or may not be room to show that toolbar-style icon, depending on screen size and orientation of the device that runs your app — action bar items with ifRoom will show as toolbar-style buttons if there is room or will fall into the overflow menu if not.
I'm using Android Studio (actually on Mac), only using real devices
This is 4.1+ only. All projects created from fresh.
CHECK - I did load support and appcompat, as best as I can understand Gradle. [A]
CHECK - onCreateOptionsMenu, etc, looks good...
CHECK - xml is good to go. (I do totally understand the showAsAction options, and tried them all.) [B] Regarding using text or an icon, I tried all permutations.
So what happens?
When I run it on a device (10+ tested). It simply shows as many action bar items as can fit (say, 5 or so). Rotation etc. works perfectly.
But it just will not show the overflow icon!! WTF?? It simply does not show, anywhere, the missing three or four items.
I have tried all this with both "Blank Activity" and "Fullscreen Activity". No matter WHAT I do, it won't show the ##$# overflow.
It's almost like the icon is just not available in the build or something??
Can any Android friends psychic this problem? It's a really "WTF" moment. Thanks in advance.
My workaround ... https://stackoverflow.com/a/22855136/294884 That works great, but you Android guys would laugh at me doing that.
[A]: (Note that I have two build.gradle files; I did it on the inner one inside app/ . Wouldn't work on the outer one.)
[B]: (Note, a common question seems to be when people don't get the difference between 'always' and 'ifRoom'. TBC that is not my problem at all: my problem is the #$## overflow simply will not appear!!)
BTW for anyone new to Android ...
https://stackoverflow.com/a/16046189/294884
that extended discussion may be very useful.
Press "File" in the top left corner of Android Studio, select "Project Structure...". A Dialog will be opened with a list of modules in the left side.
Select the module of your project, go to the tab "Dependencies", press the green "+" on the right, select "Library Dependencies" in the next Dialog you will be able to add the libraries you want.
If "Support v4" and "AppCompat" are not available you should first install "Android Support Library" and "Google Repository" via the Android SDK Manager.
That will be my best guest. Devices with hardware button don't show the 3-dots menu.
Also if the project is 4.1+ you don't need neither support-v4 nor appcompat-v7. Those might be causing some conflict.
Link to Google explanation on buttons on different devices:
http://developer.android.com/design/patterns/compatibility.html
Regarding using the build.gradle file or the dialog, well, probably yes, but I'm already used to the gradle file and never even look at the dialog, but I'm just old school.
Result!
Found Dirty Hack to force the overflow icon to be visible on devices which have the hardware menu button.
private void getOverflowMenu() {
try {
ViewConfiguration config = ViewConfiguration.get(this);
Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
if(menuKeyField != null) {
menuKeyField.setAccessible(true);
menuKeyField.setBoolean(config, false);
}
} catch (Exception e) {
e.printStackTrace();
}
}
Source:http://www.tagwith.com/question_264107_overflow-menu-not-showed-at-action-bar
I had similar problems showing action bar icons when starting to use Android Studio..
Strange that when I looked at the layout in the design screen it did showed the icons properly but when I tried to run the app both on actual device or on the emulator it showed 3 dots instead.
I do know that even on devices that have HW setting button I still see applications that shows action bar icons and not 3 dots.
Finally the only thing that helped was to do this:
// compile 'com.android.support:appcompat-v7:21.0.0'
I comment this library dependency in the gradle that fixed the problem.
I have the Something like this, when i moved my project to android studio, all action bar items instead if being displayed on the action bar, they only appear as text when pressing the hardware button menu, and when run on nexus, the three dots appear in the corner of the action bar !
i tried things suggested on this page, but had no success in showing the items on the action bar !
I want to toggle SYSTEM_UI_FLAG_HIDE_NAVIGATION or SYSTEM_UI_FLAG_LOW_PROFILE flag when compiling with AIR for ANDROID, but I don't know how to to this. Probably I had to modify the name_of_app.xml ...
I want to 'try' to switch off the menu bar in an Android Tablet, but every methods I try are a mess ....
Any Help ??
Massimo
If you want to remove the statusbar (the bar at the top), you need to go fullscreen. You can do this either in your app.xml by setting <fullscreen>true</fullscreen> or in your app at runtime by setting stage.displayState = StageDisplayState.FULL_SCREEN;
If you are trying to hide the menubar (the soft-navigation present at the bottom of Nexus devices and a limited number of other Android devices), this will set those buttons to be in their minified state as well (they are not hidden, but are set to a simple glowing circle rather than the icon). I do not know if it is possible through AIR to hide the menubar completely. It should be possible using an AIR Native Extension, assuming it is possible at all, but that may (likely is) more trouble than it is worth for such a simple task.
For future reference, you can't set most Android flags through AIR. It simply is not supported. You can set uses-permission and uses-feature in your app.xml as Manifest additions, but that is it.
i have been looking at several examples with the action bar/menu bars. but my tablet is different, at the bottom there is the back button, home, recent, three dots.....
i cannot use menu bar at the top since my app is full screen surface view that refreshes over it
i cant figure out which code is for the three dots....at the bottom left corner
http://cdn.liliputing.com/wp-content/uploads/2012/06/apps.jpg
can someone point it out pls?
The button you are seeing is the legacy menu button. It is shown for apps targeting API versions 10 and below. Specifically:
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.
For more information, read Say Goodbye to the Menu Button.
Without some sample code, there isn't much more we can do to help diagnose your problem.
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"/>