Menu items showAsAction="never" are completely gone - android

I have this menu.xml:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/action_settings"
android:orderInCategory="100"
android:icon="#drawable/ic_menu_preferences"
android:showAsAction="ifRoom"
android:title="#string/action_settings"/>
<item
android:id="#+id/action_connect"
android:orderInCategory="100"
android:icon="#drawable/ic_menu_goto"
android:showAsAction="never"
android:title="#string/action_connect"/>
<item
android:id="#+id/action_upgrade"
android:orderInCategory="100"
android:icon="#drawable/ic_menu_refresh"
android:showAsAction="never"
android:title="#string/action_upgrade"/>
</menu>
With this Activity code:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.login, menu);
return super.onCreateOptionsMenu(menu);
}
And only the action_settings action button appears. I would expect the other two to be available through the "three-dotted" menu, or the device's menu button. On the LG Optimus L3, the three-dotted menu does not appear and the device's menu button does nothing. On my Galaxy Nexus the menu does appear.
I want these other settings in a seperate menu because I don't want them to be tapped by accident. According to the documentation (emphasis mine):
The action bar provides users access to the most important action items relating to the app's current context.
If I cannot put it in the ActionBar menu, where to put the less-important action items?

It is because the LG has a hard menu button. When you press the menu button on the device, you should see the other two items.
Also, your placement of the settings icon is incorrect:
Even if there's room in the action bar, never make Settings an action
button. Always keep it in the action overflow and label it "Settings".
Place it below all other items except "Help".
http://developer.android.com/design/patterns/settings.html#flow-structure

Related

How to use two option menus in one toolbar?

I want to use two OptionsMenu in one Toolbar.
First optionMenu from Activity, and items from this menu must be on the end of Toolbar.
Second optionMenu from different Fragment's, (each has own menu) and must be before first menu.
This looks like:
In Activity:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu, menu);
return true;
}
In res/menu/menu.xml :
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.nexttek.android.menu.activity.YourActivity">
<item
android:id="#+id/action_one"
android:orderInCategory="100"
android:title="#string/action_one"
app:showAsAction="never" />
<item
android:id="#+id/action_two"
android:icon="#drawable/ic_image"
android:orderInCategory="100"
android:title="#string/action_two"
app:showAsAction="always" />
</menu>
By app:showAsAction, When and how this item should appear as an action item in the app bar. A menu item can appear as an action item only when the activity includes an app bar. Valid values,
always :Always place this item in the app bar. Avoid using this unless it's critical that the item always appear in the action bar.
collapseActionView :The action view associated with this action item (as declared by android:actionLayout or android:actionViewClass) is collapsible.
ifRoom :Only place this item in the app bar if there is room for it.
never :Never place this item in the app bar. Instead, list the item in the app bar's overflow menu.
withText :Also include the title text (defined by android:title) with the action item.

Removing the settings menu inflator from Actionbar

I have a action bar set up as this:
When I click on it a settings popup appears like this which when pressed takes me to my apps settings page.
My question is how would I remove the settings popup so that it takes me directly to my settings activity when I press the three dotted button? I tried playing around with code below but it yielded no result.
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
Goto the menu folder of your project. res>>menu and find the xml file representing the
You have to add the android:showAsAction="always" like below:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/menu"
android:title="#string/menu_settings_item"
android:showAsAction="always"
android:icon="#android:drawable/ic_menu_a" />
</menu>
Use the showAsAction parameter.
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/menu"
android:title="#string/menu_settings_item"
android:showAsAction="always"
android:icon="#android:drawable/ic_menu_a" />
</menu>
You can specify that your settings option always appears as a button on the action bar. You don't need the three dots in this case.
For instance, you can specify your action bar menu item like this (notice the "always" value):
<item android:id="#+id/action_settings"
android:title="#string/action_settings"
android:icon="#drawable/ic_action_settings"
android:showAsAction="always" />

Option menu same as like Whatsapp

I want Option menu in Action Bar same as like Whatsapp and many other applications.
Check Image shown as below :
Please help me to get this.
Android documentation says to you how to do that, here.
You need to create a new xml inside menu res folder.
An example:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="#+id/action_search"
android:icon="#drawable/ic_action_search"
android:title="#string/action_search"/>
<item android:id="#+id/action_compose"
android:icon="#drawable/ic_action_compose"
android:title="#string/action_compose" />
</menu>
android:icon: Used to specify the icon to use
android:title: The name of the action (Example, if the button does a Search it could be "Search")
android:id: The ID of the menu, you will use it to know which menu has been clicked
Then to create it in your Activity override onCreateOptionsMenu
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu items for use in the action bar
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main_activity_actions, menu);
return super.onCreateOptionsMenu(menu);
}
Replace R.menu.main_activity_actions with your menu name.
To apply the same effect like in yuor screen you should use android:showAsAction="never"
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="#+id/action_search"
android:icon="#drawable/ic_action_search"
android:title="#string/action_search"
android:showAsAction="never"
/>
<item android:id="#+id/action_compose"
android:icon="#drawable/ic_action_compose"
android:title="#string/action_compose"
android:showAsAction="never" />
</menu>
android:showAsAction=["ifRoom" | "never" | "withText" | "always" | "collapseActionView"]
android:showAsAction is used to say how Android should show the icon; if you put ifRoom Android will try to add it as icon if there are space; if you use "never" it will add it in the overflow menu.
Official doc:
ifRoom Only place this item in the Action Bar if
there is room for it.
withText Also include the title text (defined by
android:title) with the action item. You can include this value along
with one of the others as a flag set, by separating them with a pipe
|.
never Never place this item in the Action Bar.
always Always place
this item in the Action Bar. Avoid using this unless it's critical
that the item always appear in the action bar. Setting multiple items
to always appear as action items can result in them overlapping with
other UI in the action bar.
collapseActionView The action view
associated with this action item (as declared by android:actionLayout
or android:actionViewClass) is collapsible.
Introduced in API Level 14.
If you use it in API < 14 it will just be ignored.

MenuItem showing up on a bottom bar

When I inflate the menu, some of the item are showing up in the bottom bar, while the others show up in the usual options menu of Android 2.
I tried with android:uiOptions="none" in the manifest, but then the bottom bar disappear and the options menu remain.
What I want to do is to add a menu item to the action bar!
Here is the menu layout
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/menu_support"
android:icon="#drawable/icon_close"
android:showAsAction="always"
android:title="#string/menu_support"
android:visible="true"/>
<item
android:id="#+id/menu_feedback"
android:orderInCategory="100"
android:showAsAction="never"
android:title="#string/menu_feedback"/>
<item
android:id="#+id/menu_settings"
android:orderInCategory="100"
android:showAsAction="never"
android:title="#string/menu_settings"/>
</menu>
and here is the onCreateMenuOptions:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getSupportMenuInflater().inflate(R.menu.activity_main, menu); return true;
}
The options menu is always visible because the new design is for devices to not have a menu button.
I would guess that you have setDisplayShowHomeEnabled(false) and setDisplayShowTitleEnabled(false). Then when you set android:uiOptions to none, that would cause your Actionbar to go away, but keeps the options menu icon. You need to keep that as splitActionBarWhenNarrow if you're disabling the top Actionbar.
Finally to get to the crux of your question. You have one item that is set as android:showAsAction=always. That option will always show up as an icon on the action bar. The other two are set to never. They will always show up in the options menu.
never = show as an action icon on the action bar.
ifRoom = show as an action icon on the action bar if there is room on the action bar, but put in the options menu when there isn't room.
always = always shown in the option menu.
|withText = adds the hint to show the action's title if there is room on the action bar.
The rule of thumb is to only set two items as always shown as actions so that the Actionbar does not get crowded on small devices. On larger devices your ifRoom options will be displayed as Actionbar items rather than option menu items.

define Action bar overflow items

If I define the following items for my action bar:
res/menu/action_menu.xml :
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:title="label"/>
<item android:title="label1"/>
<item android:title="label2"/>
<item android:title="label3"/>
<item android:title="label4"/>
</menu>
In my Activity:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.action_menu, menu);
return true;
}
Is there anyway to allow me define certain items move to action overflow part ? and how to do it?
P.S. Action overflow part is the right-most part of action bar which hide certain items like a popup menu.
It's the other way round. You need to explicitly tell the menu which ones you want in the ActionBar and which not by setting the appropriate flags
E.g.
<item android:id="#+id/refresh"
android:title="#string/refresh"
android:icon="#drawable/reload_button"
android:showAsAction="always"/>
Here android:showAsAction tells how to handle it. Options are
always
ifRoom
never
withText
You can or options together with the pipe symbol as "always|withText"
See the android docs for action bar for more documentation.
To add something to Heiko's answer about the "overflow menu" on the action bar, this only happens if you have items set as ifRoom and there is no room for them to be displayed. On the overflow menu they only appear with a title and no icon.
On Android 4.0, the overflow menu ("3 dot spinner") is only shown on devices that don't have the physical "menu" button. You can test this on an ADV setting the option Hardware Back/Home keys option to "no".

Categories

Resources