Styling indeterminate progressbar on ActionBar

2019-01-21 11:43发布

I would like to put a progressBar on the action bar but setting

requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);  
setProgressBarIndeterminateVisibility(true);

on onCreate method produces a medium size progressBar (48dip x 48dip) I guess. I want to change the size of the progressBar but I cannot find how to do it. Can you help me please?

7条回答
家丑人穷心不美
2楼-- · 2019-01-21 12:18

I struggled with all of these solutions because I was not using actionbarsherlock. I leveraged off Vlasto Benny Lava's answer, which didn't work for me initially.

Here is what I did step by step:

1) open your styles.xml file, it should be under /res/values/styles.xml. If it doesn't exist create it.

2) paste in:

<resources xmlns:android="http://schemas.android.com/apk/res/android">
    <style name="myTheme" parent="android:Theme.Holo">
        <item name="android:actionBarStyle">@style/ActionBar.MyStyle</item>
    </style>

    <style name="ActionBar.MyStyle" parent="@android:style/Widget.Holo.ActionBar">
        <item name="android:indeterminateProgressStyle">@style/ActionBarProgressBar.MyStyle</item>
    </style>

    <style name="ActionBarProgressBar.MyStyle" parent="@android:style/Widget.Holo.ProgressBar.Small">
        <item name="android:minWidth">28dp</item>
        <item name="android:maxWidth">28dp</item>
        <item name="android:minHeight">28dp</item>
        <item name="android:maxHeight">28dp</item>
    </style> 
</resources>

One catchya I came across, you cannot use a theme name of "AppTheme" otherwise the overrides will not work. I used "MyTheme". This theme is using Holo so it has a black ActionBar as seen in image below. If you wish to have a white coloured actionbar then of course replace android:Theme.Holo with android:Theme.Holo.Light etc.

3) Edit AndroidManifest.xml.

your <application> must contain android:theme="@style/myTheme" so that the application is using your override styles from styles.xml

ie, my manifest application tag file looks something like this:

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/myTheme"
    android:name="Application Name Here" >

Because your simply shrinking down the size of the existing progress png there is no need to export any images and move them to your drawable location etc.

Here's what mine looks like, the size of the icon is perfect for me.

enter image description here

查看更多
登录 后发表回答