how to explicitelly add items to the overflow menu in the actionbar - android

I was wondering if it is possible to put items directly in the overflow menu on the actionbar. I am using ActionbarSherlock for my app (if this is relevant). I have several menu items, for instance: Add, Delete, Sort, About app, etc. These are all items for my actionbar menu. I would like to leave only "Add" outside, and put the rest in the overflow menu. Is there any way to do that?

I was wondering if it is possible to put items directly in the overflow menu on the actionbar.
Yes, set the attribute showAsAction to "never":
<item android:id="#+id/item"
android:title="#string/item"
android:showAsAction="never"/>

Related

How to know if MenuItem is in ActionBar or Overflow

First of, I'm using SherlockActionBar.
I've one MenuItem that is 'always' showed in the ActionBar and one other MenuItem that is only showed 'ifRoom'. There are also other MenuItems that are 'never' showed in the ActionBar and therefore there exists a Overflow Icon (if device has no hardwarebutton).
My question now is, how am I able to tell if the MenuItem with 'ifRoom' is currently showed or not in the ActionBar (in ActionBar or Overflow?)? I need to know that because I'm using the ShowcaseView Library to highlight these options. Therefore I have to know if I should highlight the Overflow or I can directly target to the MenuItem.
Thx
Imo there is no way to know if a menu entry is on the overflow menu via an API.
Even with "never" you can still be pushed into the overflow menu when the the title is long and your device is very narrow.
What you could try is to place an action view into your menu items and get its position on screen. If not on screen you can be certain it is pushed into the overflow menu.

How to align menu item text in Actionbar overflow menu

I'm using ActionBarSherlock to implement an actionbar in my Android application. Menu options that don't fit on this actionbar are automatically added to the overflow menu.
The problem I'm facing is that these menu options have center alignment:
How do I make sure that the menu items in the overflow menu are right-aligned, like for example in the Gmail application?
Thanks.
Never mind, I found the cause.
It turns out I was styling TextView somewhere in my theme with
<item name="android:gravity">center_horizontal</item>
and this also affected the menu items.

SearchView which overlaps ActionBar

Instead of using an ActionLayout to replace the ActionBar when pressed a MenuItem. I want that ActionLayout to overlap on the ActionBar.
Since most of the applications use this behavior I thought its the standard SearchView widget.
And since my application is for API 10 and more, i couldn't use SearchView, hence used latest ActionBarSherlock library(4.2.0), where Jake added SearchView.
The problem is, even here its like replacing the initial menu items with the ActionViewClass.
The reason i want the ActionLayout to overlap but not replace the ActionBar is, I need to have 3 MenuItems in the ActionBar and if i keep all of them as
android:showAsAction="always|collapseActionView"
they are even visible when ActionLayout is shown, which gives little width for the ActionLayout
if i am using
android:showAsAction="ifRoom"
the last icon is missing. Only 2 icons are visible.
Thank You
If you are having physical menu button (e.g. Nexus S) in your device then the dot line will not show. When you press the Menu button it’ll show up.
You may use something as this Use android:showAsAction="never" to force an action item into the overflow.

How to arrange menu items in action bar to my liking ?

i was wondering if anyone could tell me how to choose which menu items go in to the actiobar and which ones go into the overflow menu, i have five menu items and the ones i want in the actionbar go in the overflow and the one i want in the overflow are in the actiobar.
How can i rearrange the actionbars?
Any help will be appreciated
There are two things you can do.
First you can set the flag
android:showAsAction="ifRoom"
This will show items if there is room, if not they will be placed in the overflow menu.
Second, the XML file is scanned linearly. So just put your actions that you in the overflow menu to the bottom.
The documentation states
Menu items that are not promoted to an action item are available in the overflow menu, revealed by
either the device Menu button (when available) or by an "overflow menu" button in the action bar
(when the device does not include a Menu button).
Here is also an good post with more information.
How to force overflow menu on android actionbar compat?

Android Action Bar add all icon to overflow

I am updating my apps to have action bars, as Google seems to want developers to do now, and I am trying to get all the options of one app to all be in the overflow menu. I have searched far and wide but I can't seem to find anything that would make them do that. I'm pretty sure it would be something in the xml that defines the menu items. Do any of you guys know how to make all the menu options be in the overflow menu?
As CommonsWare said, showAsAction is the key.
Set android:showAsAction="never" on the if you are inflating an xml or use item.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER); if you are creating the items with code.
You should consider using android:showAsAction="ifRoom" or item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); since the actionbar will contain a lot of empty space, if you don't fill it with something else that is.
They will all be in the overflow menu by default. You have to specifically do things to your menu resource XML files to change that, notably have android:showAsAction attributes on the <item> elements.

Categories

Resources