There is an activity which has no menu item. So I want to hide the menu button. Is there any way to achieve that?
Thanks
I figured out how this can be done. In your AndroidManifest.xml, you need to specify something like the following:
<uses-sdk android:minSdkVersion="8"
android:targetSdkVersion="14" />
Basically, minSdkVersion is the minimum Android SDK version that you application supports (in my case, 2.2) and targetSdkVersion is the version you're "targetting" (i.e. your "preferred" version - in my case, that's 4.0)
By default, targetSdkVersion is the same as minSdkVersion, and if you leave that pre-Honeycomb, you're basically telling Android that your app is "legacy" and it'll always show the menu button.
If you make targetSdkVersion post-Honeycomb, then the menu button will only be shown if you actually have menu items defined.
You can do using the onPrepareOptionsMenu, where you set the menu item that you want to show to user,[http://developer.android.com/reference/android/app/Activity.html#onPrepareOptionsMenu%28android.view.Menu%29][1]
[1]: http://developer.android.com/reference/android/app/Activity.html#onPrepareOptionsMenu%28android.view.Menu%29. Do not inflate using the xml just do it manually.
Thank you.
Try this to include in your code so that the menu items are not automatically visible when you start the activity.
public boolean onCreateOptionsMenu(Menu menu){
super.onCreateOptionsMenu(menu);
//add the menu items here
return true;
}
By writing like this the menu items are visible only when you click on the menu button of the android smartphone
So I want to hide the menu button
On the vast majority of Android devices, the "menu button" is a physical thing, and cannot be hidden, any more than I can hide a mountain or a molehill.
On Honeycomb, if you do not define an options menu, you should not get the "overflow" button in the upper right corner, in the action bar.
If you are trying this on some non-compliant Android device that does its own soft menu button, you are out of luck.
Related
I want to add menu button in devices with virtual buttons like this :
If you absolutely must have a menu button on a tablet device (and it's not recommended that you do), then you should set targetSdkVersion to "10" or less in the manifest.
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.
in my app the android default menu button is not visible? why? Any help?
Refer this:
On Android Honeycomb how do I add option menu to the home bar at the bottom of the screen?
And this:
onCreate Options menu is not showing in android 3.1
You can simple edit target SDK in manifest file to force use SDK of mobile rather than tablet like this:
android:targetSdkVersion="10"
Not only should your apps stop relying on the hardware Menu button, but you should stop thinking about your activities using a “menu button” at all.Your activities should provide buttons for important user actions directly in the action bar (or elsewhere on screen). Those that can’t fit in the action bar end up in the action overflow.
In order to provide the most intuitive and consistent user experience in your apps, you should migrate your designs away from using the Menu button and toward using the action bar.
Ice Cream Sandwich rolls out to more devices, it’s important that you begin to migrate your designs to the action bar in order to promote a consistent Android user experience.See this link
Did you hook up a xml menu file to your activity ?
#Override
public boolean onCreateOptionsMenu(android.view.Menu menu) {
getMenuInflater().inflate(R.menu.xmlfilename, (android.view.Menu) menu);
return true;
}
Whether options menu at the bottom (Inflated menu) can be made permanent? The menu should be permanently inflated without the need for user to press the menu button?
whether it can be done?
whether it can be done?
No.
Besides, that menu is going away. Honeycomb and Ice Cream Sandwich are moving to the action bar pattern, where the options menu is integrated into the action bar as a drop-down menu and optional toolbar buttons.
If you want to give the user some always-visible set of actions, consider adding the action bar to your own applications. You can do this on pre-Honeycomb devices using third-party action bar implementations like ActionBarSherlock.
You can wrap your layout in a relativelayout and add buttons to the bottom. You can have it look similar too.
As Bill said you can add buttons in Relative layout and not create menu...if you need some code just tell me...
In which version you want the solution ,
in tab versions and 4.0 you can solve this problem as follows.
in manifest file add this attibute to application Tag android:uiOptions="splitActionBarWhenNarrow" so that your actionbar shows in the bottom. while your mobile is in portrait , in landscape it shows as usual on the top
and them add this flag to your menu item
MenuItem.SHOW_AS_ACTION_ALWAYS
check this link for more flags http://developer.android.com/reference/android/view/MenuItem.html i hope this will solve the issue
In some apps like Skype, FireFox and Angry Birds there is a fourth menu button (which I have tried to draw) on the right which supplies app specific buttons. I want to know how can I add this button and then show some menu when this button is clicked.
I want to know how can I add this button and then show some menu when this button is clicked.
That is the legacy MENU button. It will be supplied by the OS for older applications (i.e., not set up for Honeycomb, Ice Cream Sandwich, etc.) that have activities with options menus.
New applications being written should either:
-- Use the action bar (android:targetSdkVersion="11" or higher), in which case the options menu will appear in the upper-right corner, or
-- Integrate some other menu mechanism directly into the app UI (e.g., for games)
remove target sdk line from manifest
example:
<uses-sdk
android:minSdkVersion="7"/>