How to change android indeterminate ProgressBar color?

前端 未结 8 1033
春和景丽
春和景丽 2020-12-02 06:12

I would like to know how I can change indeterminate ProgressBar color from basis white/grey color to black ? When I change the indeterminateDrawable

相关标签:
8条回答
  • 2020-12-02 06:28
    progressBar.getIndeterminateDrawable().setColorFilter(
                getResources().getColor(Your_Color),
                android.graphics.PorterDuff.Mode.SRC_IN);
    

    and replace Your_Color with the desired color like: R.color.your_color_code

    0 讨论(0)
  • 2020-12-02 06:31

    I see other answers are quite old, in order to change the indeterminate ProgressBar color you have just to set android:indeterminateTint and android:indeterminateTintMode attributes in your ProgressBar item directly in XML:

    <ProgressBar
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:indeterminateTint="@color/colorPrimary"
        android:indeterminateTintMode="src_in"
        android:indeterminate="true" />
    

    android:indeterminateTint - Tint to apply to the indeterminate progress indicator.

    Must be a color value, in the form of "#rgb", "#argb", "#rrggbb", "#aarrggbb", or a reference to a resource @color/colorPrimary.

    android:indeterminateTintMode - Blending mode used to apply the progress indicator tint.

    Must be one of the following constant values:
    add, multiply, screen, src_atop, src_in or src_over

    Getter and Setter methods for these attributes are:

    • getIndeterminateTintList()
    • getIndeterminateTintMode()
    • setIndeterminateTintList(ColorStateList tint)
    • setIndeterminateTintMode(PorterDuff.Mode tintMode)

    All of them were added in API level 21

    0 讨论(0)
  • 2020-12-02 06:32

    I make sample project and post in in my blog. Please, look at. http://www.hrupin.com/2011/09/21/how-to-make-custom-indeterminate-progressbar-in-android-or-how-to-change-progressbar-style-or-color

    Hope, it help you

    0 讨论(0)
  • 2020-12-02 06:39
    <?xml version="1.0" encoding="UTF-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:id="@android:id/background" android:drawable="@drawable/bg" />
        <item android:id="@android:id/secondaryProgress" android:drawable="@drawable/secondary" />
        <item android:id="@android:id/progress" android:drawable="@drawable/progress" />
    </layer-list>
    
    0 讨论(0)
  • 2020-12-02 06:39

    For API less than 23 use

    progressBar.getIndeterminateDrawable().setColorFilter(
           getResources().getColor(Your_Color),
            android.graphics.PorterDuff.Mode.SRC_IN);
    

    else use

    progressBar.getIndeterminateDrawable().setColorFilter(
            ContextCompat.getColor(context, Your_Color),
            android.graphics.PorterDuff.Mode.SRC_IN);
    
    0 讨论(0)
  • 2020-12-02 06:43

    To get a ProgressBar in the default theme that is to be used on white/light back ground, 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"/>
    

    This will usually give you a black on transparent ProgressBar, but some OS installs use custom assets. If you're looking for a specific color, you'll have to roll your own drawables by following the instructions provided by CommonsWare.

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