Android Seekbar Progress Color at runtime… here is a solution to the problem.
Android Seekbar Progress Color at runtime
I want to change the search bar progress color and background color at runtime using code instead of xml. I know how to use xml (Layerlist-Shapedrawable-Clipdrawable).
I can’t change the colors in colors.xml
, so I have to set the drawable progress through code.
I’ve tried different things with LayerDrawable etc… But didn’t get any work.
Any ideas?
Solution
public void setProgressBarColor(ProgressBar progressBar, int newColor){
LayerDrawable ld = (LayerDrawable) progressBar.getProgressDrawable();
ClipDrawable d1 = (ClipDrawable) ld.findDrawableByLayerId(R.id.progressshape);
d1.setColorFilter(newColor, PorterDuff.Mode.SRC_IN);
}
When you update the progress, you will see the results.
May I?