Android - Tinting ProgressBar on pre-Lollipop devices

后端 未结 6 635
梦谈多话
梦谈多话 2020-12-31 05:27

My app\'s minimum API-level is 19 (KitKat), and contains a layout with a horizontal ProgressBar. I\'m using android:progressTint attribute to tint

6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-31 05:48

    You can wrap with ProgressBar indeterminateDrawable method for pre-Lollipop.

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
    
         Drawable drawableProgress = DrawableCompat.wrap(progressBar.getIndeterminateDrawable());
         DrawableCompat.setTint(drawableProgress, ContextCompat.getColor(getContext(), android.R.color.holo_green_light));
         progressBar.setIndeterminateDrawable(DrawableCompat.unwrap(drawableProgress));
    
    } else {
        progressBar.getIndeterminateDrawable().setColorFilter(ContextCompat.getColor(getContext(), android.R.color.holo_green_light), PorterDuff.Mode.SRC_IN);
    }
    

提交回复
热议问题