How to set Progressbar Color Programmatically in Android Java

Change Android ProgressBar Color Programmatically in Java

Changing the progress bar color in the xml can be a headache, because you will have to change values in styles and colors or the theme editor in android studio, so here is the explanation to set the color code of your progress bar programmatically,

You still need to have a progressbar defined in your xml, this code will not create a progressbar, only will change its color


First, identify and initialize the Progressbar

ProgressBar loadingProgressBar = (ProgressBar) findViewById(R.id.prog);

Then use the below code to change the progressbar color

loadingProgressBar.getProgressDrawable().setColorFilter(
        Color.parseColor("#2a4c6b"), android.graphics.PorterDuff.Mode.SRC_IN);

Here i used this green color code “#2a4c6b”, you can change this to your desired color code.

Related Posts

How to Export Project Zip from Android Studio

How to Export Source Code ZIP in Android Studio Sometimes, you will need export the source code of your android studio app project, to share it with…

Fix Plugin [id: ‘com.android.application’, version: ‘7.1.3’, apply: false] was not found in any of the following sources

Here is how to fix Plugin [id: ‘com.android.application’, version: ‘7.1.3’, apply: false] was not found in any of the following sources This error is caused by mismatching…

Get Age from Date of Birth in Java Android

Here is how to get a user’s age from date of birth If you need get a user’s age from a given date of birth string, this…

How to Check if String Array Contains a Specific String in Android

Here is how to get a specific value or String from Array in Android To check if a string array contains a specific string, you can use…

Make Android WebView Support Razorpay Payment

How to Support Razorpay Payment and UPI in Android WebView? Android webview is inexpensive and easy way to make apps for websites. But to support some specific…

Leave a Reply

Your email address will not be published. Required fields are marked *