Basically I am inflating a menu
public boolean onPrepareOptionsMenu(Menu menu) {
menu.clear();
globalMenu = menu;
getSupportMenuInflater().inflate(R.layout.menu_refresh, menu);
return super.onPrepareOptionsMenu(menu);
}
menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/menu_refresh"
android:showAsAction="never"
android:title="#string/refresh"/>
<item
android:id="#+id/menu_24hours"
android:showAsAction="never"
android:title="#string/twentyfour_hours"/>
<item
android:id="#+id/menu_1week"
android:showAsAction="never"
android:title="#string/one_week"/>
<item
android:id="#+id/menu_1month"
android:showAsAction="never"
android:title="#string/one_month"/>
<item
android:id="#+id/menu_3month"
android:showAsAction="never"
android:title="#string/three_month"/>
<item
android:id="#+id/menu_6month"
android:showAsAction="never"
android:title="#string/six_month"/>
</menu>
whats happening, is that none of them are showing in 3 dots format.In ice cream sandwich you have to click the button menu on hardware, in nexus it shows 3 dots..
i need everywhere to have it as 3 dots, no device uniqueness.
However if i do this in my menu...
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/menu_refresh"
android:showAsAction="always"
android:icon="#drawable/ic_action_refresh_default" />
</menu>
this shows up in actionbardsherlock on top, on all devices. no menu hardware key.
Try creating dummy actionButton which have 3 dots as the icon. This is what I do if I need 3 dots button to be shown on all devices (Especially Samsung devices which have hardware menu keys).
Note that this is actually a hack
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/menu_dummy_overflow"
android:icon="#drawable/ic_action_ic_overflow"
android:showAsAction="always"
android:title="#string/more">
<menu>
<item
android:id="#+id/menu_open_browser"
android:icon="#drawable/ic_action_ic_browser"
android:showAsAction="never"
android:title="#string/opeinInBrowser">
</item>
</menu>
</item>
</menu>
This is something that's decided by the Android OS build that is running. The bad news is that it means you have little control over it. The good news is that it means the user will see the same behaviour on every app on their phone, so they will be expecting it anyway.
You could mimic the behaviour by manually adding an overflow item to your menu and putting your overflow items into a sub-menu of that item. The downside of this is that the number of items you show is fixed. You won't get the benefit of a tablet in landscape mode showing more items in the ActionBar
Related
it seems that what ever i did i cant set the icons visible to the tool bar, i've tried to do researches on many platforms, but nothing helped.
here is the xml menu:
<?xml version="1.0" encoding="utf-8" ?>
<menu
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/event_ic"
android:icon="#mipmap/ic_event"
android:title="profile"
android:showAsAction="always"
/>
<item
android:id="#+id/details_menu"
android:title="details"
android:showAsAction="never"/>
</menu>
you can see that even if i set the android:showAsAction to always, i still get the event item in the pop up menu without the icon.
I have an app with a NoActionBar theme. In my main activity I have an options menu that I created manually on the top of the screen (or by utilizing the built in device's options button).
In this main activity, I have a fragment with a listView where I apply the action mode long click functionality, to show the contextual action bar (CAB) for further user options.
Now, I try adding an options item to my CAB so it will contain some options like selecting all items in the listView, but since it's an item of the CAB, I can't really show the popup menu like in a regular activity. Further more, I want all the options menu callbacks (such as onOptionsItemSelected) to stay in the context of the CAB, in order to be able to continue to perform actions on the CAB.
Here's the code of my CAB:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/action_delete"
android:orderInCategory="100"
app:showAsAction="always"
android:icon="#drawable/ic_action_delete"
android:title="Delete"/>
<item
android:id="#+id/action_overflow"
app:showAsAction="always"
android:orderInCategory="200"
android:icon="#drawable/ic_action_overflow"
android:title="Options"
android:visible="false"/>
</menu>
Apparently I missed the built in feature of the CAB - a built in overflow menu that collapses some of the actions' items once the screen is too small to show them all.
Another manipulation that needs to be done in order to always collapse certain actions under that overflow menu is to set for each one of them:
android:showAsAction="never"
app:showAsAction="never"
So, say we have 3 actions (delete, selece_all, add) in the CAB, and we want two of them (select_all, add) to be collapsed always under the built in overflow menu, we'll set this in the CAB's xml:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:mm="http://schemas.android.com/apk/res-auto">
<item
android:id="#+id/action_delete"
android:orderInCategory="100"
mm:showAsAction="always"
android:icon="#drawable/ic_action_delete"
android:title="Delete"/>
<item
android:id="#+id/action_select"
android:orderInCategory="200"
android:showAsAction="never"
mm:showAsAction="never"
android:title="#string/select_all"/>
<item
android:id="#+id/action_add"
android:orderInCategory="300"
android:showAsAction="never"
mm:showAsAction="never"
android:title="#string/button_add"/>
I have an app (for 4.0 and above) which has couple of MenuItems in the ActionBar (one with 'always' and the rest with 'ifRoom' or 'never' property).
So the issue goes like this...
If I launch the app in landscape mode, the ActionBar looks like the following:
When I rotate to landscape from portrait, the ActionBar looks like this:
As you can see, more icons appear than they should be, i.e no space is left for title bar and the tabs menu (Navigation Menu). Actually, the 4 items are shown in the portrait mode (it's a split ActionBar) and it seems that the Android doesn't realise that there's no SplitActionBar there anymore.
Please suggest what I can do to fix this? :)
Edit
My menu.xml:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/action_share"
android:icon="#drawable/ic_menu_share"
android:showAsAction="always"
android:title="#string/share"/>
<item
android:id="#+id/action_viewToggle"
android:icon="#drawable/ic_menu_view_as_grid"
android:showAsAction="ifRoom"
android:title="#string/switch_view"/>
<item
android:id="#+id/action_upload"
android:icon="#drawable/ic_menu_upload"
android:showAsAction="ifRoom"
android:title="#string/upload"/>
<item
android:id="#+id/action_newFolder"
android:icon="#drawable/ic_menu_new_folder"
android:showAsAction="ifRoom"
android:title="#string/create_folder"/>
<item
android:id="#+id/action_multiselect"
android:icon="#drawable/ic_menu_select_all"
android:showAsAction="ifRoom"
android:title="#string/selection_mode"/>
<item
android:id="#+id/action_refresh"
android:icon="#drawable/ic_menu_refresh"
android:showAsAction="ifRoom"
android:title="#string/refresh"/>
<item
android:id="#+id/action_settings"
android:icon="#drawable/ic_menu_settings"
android:showAsAction="never"
android:title="#string/action_settings"/>
</menu>
Make sure you take care of each menu item visibility in your menu.xml file, check out the xml ShowAsAction attribute.
here's an example:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/SOME_MENU_ITEM"
android:icon="#drawable/SOME_ICON"
android:showAsAction="ifRoom" | "never" | "withText" | "always" | "collapseActionView"
android:title="SOME_TITLE"/>
.
.
One of the important attribute xml for menu items is,
android:showAsAction ,that defines the visibility of the action item.
From your code it is evident that if there is room in action bar it'll display it.
So if you don't want it to appear specify android:showAsAction value as never so that whatever the orientation is it'll appear only in the overflow menu.
I'm using ActionBarSherlock to provide a unified UI for my Android 2.x and Android 4.x users. I have a menu with 6 items.
On a 2.x, 480px wide device with an hdpi screen, only 5 of the icons show. The device has a hardware Menu button, but when I tap it, nothing shows up. I expected it to popup and show the Action that wasn't able to fit.
I expect either the three-vertical-dots button to appear in the ActionBar to show a dropdown with the overflowed actions or I expect the physical Menu button to show the old style menu with the overflowed actions.
What am I missing or what am I doing wrong?
Here is my defined menu.xml:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/add"
android:icon="#drawable/ic_menu_btn_add"
android:showAsAction="always"
android:title="Add"/>
<item
android:id="#+id/calculateNPV"
android:icon="#drawable/menu_icon_npv"
android:showAsAction="always"
android:title="NPV"/>
<item
android:id="#+id/calculateIRR"
android:icon="#drawable/menu_icon_irr"
android:showAsAction="always"
android:title="IRR/YR"/>
<item
android:id="#+id/send"
android:icon="#android:drawable/ic_menu_share"
android:showAsAction="always"
android:title="#string/share_pdf"/>
<item
android:id="#+id/graph"
android:icon="#drawable/ic_menu_gallery"
android:showAsAction="always"
android:title="#string/view_cashflow_diagram"/>
<item
android:id="#+id/deleteReorder"
android:icon="#drawable/ic_menu_clear_playlist"
android:showAsAction="always"
android:title="#string/delete_reorder_cashflows"/>
</menu>
I am having 5 items in the menu, and I only want to show 2 at the time.
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/menu_start"
android:icon="#drawable/ic_action_start"
android:orderInCategory="93"
android:showAsAction="ifRoom|withText"
android:title="#string/menu_start"/>
<item
android:id="#+id/menu_filter"
android:icon="#drawable/filter_icon"
android:orderInCategory="94"
android:showAsAction="ifRoom|withText"
android:title="#string/menu_filters"/>
<item
android:id="#+id/menu_refresh"
android:icon="#drawable/ic_menu_refresh"
android:orderInCategory="95"
android:showAsAction="never"
android:title="#string/menu_refresh"/>
<item
android:id="#+id/menu_delete_all"
android:icon="#drawable/ic_menu_delete"
android:orderInCategory="96"
android:showAsAction="never"
android:title="#string/menu_delete_all"/>
<item
android:id="#+id/menu_show_hidden"
android:orderInCategory="97"
android:showAsAction="never"
android:icon="#drawable/ic_menu_show_hidden"
android:title="#string/menu_show_hidden"/>
</menu>
When I test this on Galaxy Nexus, or any device that doesnt have menu button, it creates an overflow menu, however it does not add to be the third one as I would liked, but it removes my second icon and replaces it.
How do I have to setup the actionbar, to have 2 icons on devices without menu button, and 2 + (overflow) on devices that have?
Thanks !