Reputation: 5111
I want to change color of a progress bar in android in a particular activity only not in the whole app.
I am using the below progress bar :
<ProgressBar
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/progressBar"
android:layout_centerInParent="true"/>
mProgressBar = (ProgressBar) findViewById(R.id.loading);
mProgressBar.getIndeterminateDrawable().setColorFilter(ContextCompat.getColor(mContext, R.color.white),
PorterDuff.Mode.SRC_IN);
Changing color of this progress bar using the above code. The above code changing the color of all progress bars through out the app.
I want to change the color of this progress bar only in this particular activity.
How can I do this, please help me. Thank you so much in advanced.
Upvotes: 0
Views: 1329
Reputation: 3873
Use this method better than programmatically in Java.
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/progressBar1"
android:layout_centerInParent="true"
android:progressDrawable="@drawable/progress_layer01"
android:indeterminate="false" />
progress_layer01.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>
<solid android:color="#f1f1f1"/>
</shape>
</item>
<item android:id="@android:id/progress">
<clip>
<shape>
<solid android:color="#FF0000"/>
</shape>
</clip>
</item>
</layer-list>
In your JAVA code:
progressBar1.setProgress(45);
Upvotes: 0
Reputation: 910
Try to set a colorFilter, like this:
progressBar.getProgressDrawable().setColorFilter(Color.GREEN, Mode.SRC_IN);
Upvotes: 3