Lollipop Progress Bar Tinting

前端 未结 5 1621
再見小時候
再見小時候 2021-02-05 02:49

I\'m on a Lollipop device (MotoG 2014), I read about progress bar tinting, but this is not working...I get the default progress bar color. What am I missing here?



        
5条回答
  •  日久生厌
    2021-02-05 03:15

    To avoid tinting the ProgressBar background as well, you should get a reference to the exact bitmap from the inner ProgressBar LayerDrawable. This is a hacky way of doing it, but it works.

    LayerDrawable layerDrawable = (LayerDrawable) progressBar.getProgressDrawable();
    Drawable drawable = layerDrawable.getDrawable(2); // The progress bitmap
    drawable.setColorFilter(color, PorterDuff.Mode.SRC_IN);
    

提交回复
热议问题