Put indeterminate spinner in ActionBar - android

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.

Related

Creating a popup options menu in a contextual action bar

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"/>

Items in Action Bar won't show in App

I have a problem: I want to put a search Icon on the Action Bar. In Android Studio it shows it on the Action Bar, but when I open the App it only shows it in the menu..
Here is my xml code:
<item
android:id="#+id/action_settings"
android:title="#string/action_settings"
android:orderInCategory="100"
android:showAsAction="never" />
<item
android:id="#+id/action_search"
android:icon="#drawable/ic_action_search"
android:showAsAction="ifRoom"
android:title="#string/action_search"/>
I tried many things but it wont work. I hope you can help me.
It still doesn't work I really don't have a clue why.
You're not specifying your ActionView class, which is probably part of the problem. Here is the xml for a search action view that I use in one of my applications that works fine.
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/search_user"
android:actionViewClass="android.widget.SearchView"
android:icon="#drawable/magnifing_glass"
android:showAsAction="ifRoom|collapseActionView"
android:title="#string/action_search"/>
</menu>
EDIT:
If you're not trying to use it as an ActionView, disregard the above and use showAsAction="always".
Your problem is either that there is not enough space on the action bar to display the icon, or your device has a dedicated menu button.

Android menu item not showing drawable

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

How to get options from the options menu into title bar ActionBar Sherlock android

I am trying to get my options to show up in the Title Bar. I'm using ActionBarSherlock and I can figure out how to remove the title in the title bar, but would like to replace the text with 2 options from my options menu.
I'm using this code, EmpubLite as an example for my application, but I can't figure out how Mark (the commonsware guy) got the icons from his options menu in the title bar. My options show up at the bottom in the action bar and this is taking up unnecessary room on the screen. I've been looking through examples here, but can't seem to find out exactly how to get options in the title bar. I'm hoping Mark (or someone) can explain.
would like to replace the text with 2 options from my options menu
Um, unless that happens automatically by removing the title, I suspect that's not possible.
but I can't figure out how Mark (the commonsware guy) got the icons from his options menu in the title bar
Well, you see, that's covered in this delightful little book... :-)
More seriously, android:showAsAction controls whether items should be in the overflow area (never), should be in the action bar (ifRoom), or really really should be in the action bar (always). That being said, always is a hint, not a demand, and the OS may still put your action bar items in the overflow on smaller screen sizes.
You did not state which of the EmPubLite series you are experimenting with. Early on, the items are all set to never:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/help"
android:icon="#android:drawable/ic_menu_help"
android:showAsAction="never"
android:title="#string/help"/>
<item
android:id="#+id/about"
android:icon="#android:drawable/ic_menu_info_details"
android:showAsAction="never"
android:title="#string/about">
</item>
</menu>
By the end of the series, we have some that ideally go into the action bar:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/notes"
android:icon="#android:drawable/ic_menu_edit"
android:showAsAction="ifRoom|withText"
android:title="#string/notes">
</item>
<item
android:id="#+id/update"
android:icon="#android:drawable/ic_menu_save"
android:showAsAction="ifRoom|withText"
android:title="#string/download_update">
</item>
<item
android:id="#+id/settings"
android:icon="#android:drawable/ic_menu_preferences"
android:showAsAction="never"
android:title="#string/settings">
</item>
<item
android:id="#+id/help"
android:icon="#android:drawable/ic_menu_help"
android:showAsAction="never"
android:title="#string/help">
</item>
<item
android:id="#+id/about"
android:icon="#android:drawable/ic_menu_info_details"
android:showAsAction="never"
android:title="#string/about">
</item>
</menu>
My options show up at the bottom in the action bar and this is taking up unnecessary room on the screen.
You have android:uiOptions="splitActionBarWhenNarrow" set in your manifest somewhere, then.

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