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.