Search code examples
androidactionbarsherlock

How to show Indeterminate Progress bar when Refresh button is pressed in ActionBarSherlock?


How to show Indeterminate ProgressBar when Refresh button is pressed in ActionBarSherlock and again show Refresh Button when ViewGroup on refreshed?

Update 1: I have a answer here which is incomplete. I am placing a bounty on question so that more developers can help build a good answer which can useful to others in future.

How can we show a Indeterminate ProgressBar which looks like the one shown in the image belowenter image description here


Solution

  • It seems like ActionBarSherlock doesn't provide specific method to animate a refresh MenuItem.

    What you can do (by using classic android API) is to use the setActionView(int resId) method and give the id of a layout with a ProgressBar in it.

    At the beginning of your refresh action just call :

    item.setActionView(R.layout.refresh_menuitem);
    

    And when your refresh action is finished call :

    item.setActionView(null);
    

    Here is a sample of what your layout file refresh_menuitem.xml can have :

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:addStatesFromChildren="true"
                  android:focusable="true"
                  android:paddingLeft="4dp"
                  android:paddingRight="4dp"
                  android:gravity="center"
                  style="?attr/actionButtonStyle">
        <ProgressBar
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:focusable="true"
                style="@android:style/Widget.ProgressBar.Small"/>
    </LinearLayout>