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>
Related
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
I developed an application and I wanted to have some less common feature under the 3 square button
On android 4.0, I have the result I want : (3 square button, when I click on it, I have the others features)
On android 2.3, the device has a menu physical button but the feature aren't available because they are overrided (the menu button call the sliding menu).
Is it possible to show the 3 square button on all device with action bar sherlock ? and use the menu physical button to show the sliding menu ?
My menu definition :
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/menu_download"
android:icon="#drawable/ic_menu_d_download"
android:showAsAction="always|withText"
android:title="#string/download"/>
<item
android:id="#+id/menu_print"
android:icon="#drawable/ic_menu_d_print"
android:showAsAction="withText"
android:title="#string/print"/>
<item
android:id="#+id/menu_share"
android:icon="#drawable/ic_menu_d_share"
android:showAsAction="always|withText"
android:title="#string/share"/>
<item
android:id="#+id/menu_accept"
android:icon="#drawable/ic_menu_d_accept"
android:showAsAction="always|withText"
android:title="#string/ok"/>
<item
android:id="#+id/menu_delete"
android:icon="#drawable/ic_menu_d_delete"
android:showAsAction="withText"
android:title="#string/delete"/>
</menu>
When I see the documentation of android:showAsAction, I didn't find a value that would help http://developer.android.com/guide/topics/resources/menu-resource.html
Regards
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.
Im using the ActionBarActivity on my activity and inflating the following menu
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:microecs="http://schemas.android.com/apk/res-auto">
<item android:id="#+id/menu_refresh"
android:icon="#drawable/ic_action_refresh"
android:title="#string/description_refresh"
android:orderInCategory="1"
microecs:showAsAction="ifRoom" />
<!--TODO: get a good logout icon-->
<item
android:id="#+id/menu_logoff"
android:icon="#drawable/ic_action_logout"
android:title="#string/description_logoff"
android:orderInCategory="2"
microecs:showAsAction="never" />
</menu>
The second menu item drawable that i want to appear as a menu and not in the action bar doesn't not appear in my S4 (running 4.3) and also on lower devices running 2.3.7
Just update your code with following code.
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:microecs="http://schemas.android.com/apk/res-auto">
<item android:id="#+id/menu_refresh"
android:icon="#drawable/ic_action_refresh"
android:title="#string/description_refresh"
android:orderInCategory="1"
microecs:showAsAction="ifRoom" />
<!--TODO: get a good logout icon-->
<item
android:id="#+id/menu_logoff"
android:icon="#drawable/ic_action_logout"
android:title="#string/description_logoff"
android:orderInCategory="2"
microecs:showAsAction="ifRoom" />
</menu>
Whenever you are using never then it dont place that item in the Action Bar.
For about menu refer this link.
This is not possible by design. Overflow menus from the action bar don't show icons - that's just a design decision Google made.
You can check more, e.g. here: Displaying icon for menu items of Action Bar in Honeycomb android 3.0
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 !