Android menu item not showing drawable - android

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

Related

android fragment activity menu

I have a class that extends FragmentActivity. No I want to show my menu items at the top of the screen like in actionbar. How can I do this ?
I have created the menu items and they are visible hen the hardware button for menu is pressesd but I want to sho them at the top of the screen.
Basically, this happens in devices with physical menu button. In devices without that button, all options are displayed in the action bar.
You can force a menu item to be displayed in the action bar by addind "showAlways" to the item that you want.
showAsAction=“always”
An small 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"
android:showAsAction="always" />
<item android:id="#+id/action_settings"
android:title="#string/action_settings"
android:showAsAction="always" />
</menu>
You must need to ensure that you have enough space for the menu items.
To ensure that I'll have enough space, I use to create a menu with only one item. Then, inside this item, I create another menu. This way, only one button is displayed and all items appear in a floating pop up menu. The main idea is below:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="#+id/overflow_item"
android:icon="#drawable/ic_overflow_icon"
android:title="#string/options"
android:showAsAction="always" />
<menu>
<item android:id="#+id/action_clear"
android:title="#string/clear"
android:showAsAction="always" />
</menu>
</menu>

Show the same UI for menu with actionbarsherlock on device pre 2.3 and post 4.0

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

Put indeterminate spinner in ActionBar

In my action bar I have 2 different icons that load different data. I want to remove my popup dialog's when the data is loading and replace the icon in the action bar with an indeterminate spinner whilst the data's loading, and then go back to the original icon.
What will be the best way of doing this? Will I need a custom action bar layout? At the moment my action bar icon's are just set up from a XML file
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/action_settings"
android:title="#string/clear_stored_data"
android:orderInCategory="100"
android:icon="#drawable/content_discard"
android:showAsAction="never" />
<item android:id="#+id/refresh_list"
android:title="#string/refresh_list"
android:orderInCategory="100"
android:icon="#drawable/navigation_refresh"
android:showAsAction="always" />
<item android:id="#+id/search_using_location"
android:title="#string/search_using_current_location_short"
android:orderInCategory="100"
android:icon="#drawable/device_access_location_found"
android:showAsAction="always" />
You might want to take a look at the RefreshActionItem project on Github. It's a third party component that does exactly what you are looking for.

Overflow ActionBar actions not showing in Menu for Android 2.x

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>

Android 3.0: Changing order of icons in the action bar

I am working with the Android 3.0.
I have in the action bar 3 items and one of them is the menu of the application, it also has sub-menu in it.
I want to change the order of the icons so the menu won't be in the right place, I want it to be between the two other items. I tried to change the order in the xml with no success.
Does anyone has an idea how to set the order?
Try setting android:menuCategory and android:orderInCategory for your menu items to set the ordering.
Example:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/launch_search"
android:icon="#android:drawable/ic_menu_search"
android:title="#string/search_programs"
android:menuCategory="container"
android:orderInCategory="2"
android:showAsAction="always" />
<item android:id="#+id/preferences_screen"
android:icon="#android:drawable/ic_menu_preferences"
android:title="#string/preferences" />
<item android:id="#+id/refresh"
android:icon="#drawable/ic_menu_refresh"
android:menuCategory="container"
android:orderInCategory="1"
android:title="#string/refresh_items"
android:showAsAction="ifRoom" />
</menu>
It will have the same effect as declaring launch_search -action as last, but this way you'll have your actions in the right order for 2.x and older devices while being able to control action ordering for 3.x -devices.
The menu will always go to the right, you cannot control its placement.

Categories

Resources