Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change progress bar progress color?

I created this progress bar for my app, but I cant get that yellow orangy color that appears to change to something like red or blue.

<ProgressBar
        android:id="@+id/progress_bar"
        style="@android:style/Widget.ProgressBar.Horizontal"
        android:layout_width="250sp"
        android:layout_height="wrap_content"
        android:progress="2"
        android:layout_marginTop="82dp"
        android:max="3"
        android:indeterminate="false"
        android:layout_below="@+id/imageView"
        android:layout_centerHorizontal="true" />

above is my progress bar xml code.

Any help guys? :)

Thanks so much in advance! :)

like image 956
AmateurProgrammer Avatar asked Jun 30 '16 10:06

AmateurProgrammer


People also ask

How do I customize my progress bar in HTML?

In the stylesheet, we actually can use the element selector to target and add style rules to <progress> element. In this example, we change the background color, remove the border line, and make it rounded by adding a border radius at half of its height.

How do I change the color of my kotlin progress bar?

If you only want to change the progress bar color, you can simply use a color filter in your Activity's onCreate() method: ProgressBar progressbar = (ProgressBar) findViewById(R. id. progressbar); int color = 0xFF00FF00; progressbar.


2 Answers

If android version is 5.0 and above you just need to set

android:indeterminateTint="@color/BLACK"
android:indeterminateTintMode="src_in"

For lower version I use this

mProgressBar.getIndeterminateDrawable().setColorFilter(getResources()
.getColor(R.color.primary_color),PorterDuff.Mode.SRC_IN);
like image 131
thealeksandr Avatar answered Sep 19 '22 12:09

thealeksandr


Create a new XML file in your drawable folder called something like custom_progress_bar.xml and paste this there:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <!-- Define the background properties like color etc -->
    <item android:id="@android:id/background">
        <clip>
            <shape>
                <solid android:color="#000000" />
            </shape>
        </clip>
    </item>
    <!-- Define the progress properties like start color, end color etc -->
    <item android:id="@android:id/progress">
        <clip>
            <shape>
                <solid android:color="#FFFFFF" />
            </shape>
        </clip>
    </item>

</layer-list>

And in your <ProgressBar> add this attribute:

android:progressDrawable="@drawable/custom_progress_bar"

Change the 2 colors to your own preference. I put #FFFFFF and #000000 which are white and black.

like image 21
Vucko Avatar answered Sep 22 '22 12:09

Vucko