Change horizontal progress bar indeterminate color

2019-09-02 08:47发布

问题:

Is it possible to change horizontal indeterminate color? As of now it is take standard theme color.

I would like to change it to orange?

I know we have change the circle color I am not sure to change the horizontal color tried Theme, custom progress bar in drawable etc but couldn't get work.

Here is the XML:

<ProgressBar
   android:id="@+id/status_progress"
   style="?android:attr/progressBarStyleHorizontal"
   android:layout_width="match_parent"
   android:layout_height="15dp"
   android:layout_below="@id/status_text"
   android:indeterminate="true"
   android:indeterminateOnly="true" />

回答1:

progressBar.getIndeterminateDrawable()
    .setColorFilter(progressBar.getContext().getResources().getColor(<colorId>),
        PorterDuff.Mode.SRC_IN);


回答2:

use a custom xml drawable orangePogress.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
    <shape>
        <corners android:radius="5dip" />
        <gradient
                android:startColor="#ff9d9e9d"
                android:centerColor="#ff5a5d5a"
                android:centerY="0.75"
                android:endColor="#ff747674"
                android:angle="270"
        />
    </shape>
</item>

<item android:id="@android:id/secondaryProgress">
    <clip>
        <shape>
            <corners android:radius="5dip" />
            <gradient
                android:startColor="#ff9d9e9d"
                android:centerColor="#ff5a5d5a"
                android:centerY="0.75"
                android:endColor="#ff747674"
                android:angle="270"
            />
        </shape>
    </clip>
</item>
<item
    android:id="@android:id/progress"
>
    <clip>
        <shape>
            <corners
                android:radius="5dip" />
            <gradient
                android:startColor="#FF6600"
                android:endColor="#FF9933"
                android:angle="270" />
        </shape>
    </clip>
</item>

</layer-list>

and then in your progressbar

<ProgressBar
    android:id="@+id/ProgressBar"
    style="?android:attr/progressBarStyleHorizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:indeterminate="false"
    android:progressDrawable="@drawable/orangePogress" />