Android: Changing the Default Indeterminate Progress Size in ActionBarSherlock

Just a quick post on how to change the default size of the Indeterminate Progress animation when using ActionBarSherlock (ABS). This uses the dark halo them for Android 4.0.1 but tested and working from version 2.3.2 to 4.0.1 of the SDK. Here are the before and after shots:

Grab the progress_small_holo.xml and associated images from the Android SDK (15) and move them to your project (from your SDK location: android/platforms/android-15/data/res/drawable). We will be using this to style the progress animation in the ActionBar for ABS Set up your style.xml as follows:

values/styles.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="Dark" parent="Theme.Sherlock">
        <item name="actionBarStyle">@style/Widget.Styled.ActionBar</item>
        <item name="android:actionBarStyle">@style/Widget.Styled.ActionBar</item>
    </style>

    <style name="Widget.Styled.ActionBar" parent="Widget.Sherlock.Light.ActionBar">
        <item name="android:indeterminateProgressStyle">@style/IndeterminateProgress</item> 
        <item name="indeterminateProgressStyle">@style/IndeterminateProgress</item> 
    </style>

    <style name="IndeterminateProgress" parent="@android:style/Widget.ProgressBar.Small"> 
       <item name="android:indeterminateDrawable">@drawable/progress_small_holo</item> 
   </style> 
</resource>

values-v14/styles.xml (ICS)

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="Dark" parent="Theme.Sherlock">
        <item name="actionBarStyle">@style/Widget.Styled.ActionBar</item>
        <item name="android:actionBarStyle">@style/Widget.Styled.ActionBar</item>
    </style>

    <style name="Widget.Styled.ActionBar" parent="Widget.Sherlock.Light.ActionBar">
        <item name="android:indeterminateProgressStyle">@style/IndeterminateProgress</item> 
        <item name="indeterminateProgressStyle">@style/IndeterminateProgress</item> 
    </style>

    <style name="IndeterminateProgress" parent="@android:style/Widget.ProgressBar.Small"/> 

</resource>

You could also add some additional sizing if you want to center the progress animation in the actionbar:

<style name="IndeterminateProgress" parent="@android:style/Widget.ProgressBar.Small">
       <item name="android:minWidth">48dp</item> 
</style>

You can see more of the discussion on this thread or from StackOver.

-Mister

9 Comments

  1. Hi! I wish to do exactly what you outlined. I added the required files, styles.xml, etc. but the progress indicator is still large. Do I need to modify the AndroidManifest.xml or something else to “hook it up”? I’m still fairly new to Android and have not yet messed with styles. Thanks!

  2. Great thanks! I think you may have your styles and styles-v14 are the wrong way round. For my devices the custom drawable does not work for pre v14 so just using @android:style/Widget.ProgressBar.Small works in those cases.

      1. I am using this
        supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
        etSupportProgressBarIndeterminateVisibility(true)

      2. It’s more complicated than that, when you use ActionBarCompat you need a totally different way to access the menu item and change the refresh button. Again, take a look at the Google ioSched application on GitHub for the example.

Comments are closed.