Android Seekbar run time color

I want to change the stroke color and background color at runtime with code, not xml. I know how to do this with xml (Layerlist-Shapedrawable-Clipdrawable) I cannot change the colors in colors.xml , so I need to set the progress available for the code. I already tried different things with LayerDrawable, etc., but got nothing. Any ideas?

+4
source share
1 answer
 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 progress, you will see the result.

This is normal?

0
source

Source: https://habr.com/ru/post/1439093/


All Articles