How to change the color of an indefinite ProgressBar?

后端 未结 7 893
萌比男神i
萌比男神i 2020-12-14 17:50

I have a progressbar with the following style: style=\"?android:attr/android:progressBarStyleSmall\"

Sadly the bar is nearly white and in my case displ

相关标签:
7条回答
  • 2020-12-14 18:10
    progressBar.getIndeterminateDrawable().setColorFilter(
                getResources().getColor(R.color.light_light_purple),
                android.graphics.PorterDuff.Mode.SRC_IN);
    

    This code changes the default holo inderminate drawable color to your own color. Define your color code and replace R.color.light_light_purple to R.color.your_color_code.

    0 讨论(0)
  • 2020-12-14 18:10

    I had a very hard time trying to change it's color. To solve it, I got android's src code and did my own ProgressBar class.

    Not the best answer, but it worked for me.

    0 讨论(0)
  • 2020-12-14 18:11

    To get a black ProgressBar, use one of the inverse styles:

    <ProgressBar style="@android:style/Widget.ProgressBar.Inverse"/>
    <ProgressBar style="@android:style/Widget.ProgressBar.Large.Inverse"/>
    <ProgressBar style="@android:style/Widget.ProgressBar.Small.Inverse"/>
    
    0 讨论(0)
  • 2020-12-14 18:11

    And the answer was already on SO:

    stackoverflow.com/questions/2020882/how-to-change-progress-bars-progress-color-in-android

    You can simply change the whole drawable that is shown in the progressbar via the android:indeterminateDrawable attribute.

    0 讨论(0)
  • 2020-12-14 18:14

    The reason why the bar is of that color is because of the style you have selected. That is a fixed style and uses the system themes for the generation of UI elements.

    Look at the source code from here. This progressBarStyleSmall attribute uses the styles defined here.

    <style name="Widget.ProgressBar.Small">
        <item name="android:indeterminateDrawable">@android:drawable/progress_small_white</item>
        <item name="android:minWidth">16dip</item>
        <item name="android:maxWidth">16dip</item>
        <item name="android:minHeight">16dip</item>
        <item name="android:maxHeight">16dip</item>
    </style>
    

    Just create a custom style following the example from the android source code. You would need to replace the android:indeterminateDrawable to what you want.

    0 讨论(0)
  • 2020-12-14 18:19

    Just a note, to use

    <ProgressBar style="@android:style/Widget.ProgressBar.Inverse"/> 
    

    or any of the inverse progress bars, you have to set your minimum android sdk requirement to level 4 (Android 1.6).

    0 讨论(0)
提交回复
热议问题