Skip to content

Instantly share code, notes, and snippets.

@ahmedre
Created December 1, 2016 11:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahmedre/4387b219c11a145ecdbbf40b2d63de01 to your computer and use it in GitHub Desktop.
Save ahmedre/4387b219c11a145ecdbbf40b2d63de01 to your computer and use it in GitHub Desktop.
Tint a SeekBar
// backward-compatible means of tinting a progress bar
public void tintProgressDrawable(SeekBar seekBar, int tintColor) {
final Drawable progressDrawable = seekBar.getProgressDrawable();
if (progressDrawable != null) {
if (progressDrawable instanceof LayerDrawable) {
LayerDrawable ld = (LayerDrawable) progressDrawable;
int layers = ld.getNumberOfLayers();
for (int i = 0; i < layers; i++) {
ld.getDrawable(i).mutate().setColorFilter(tintColor, PorterDuff.Mode.SRC_ATOP);
}
} else {
progressDrawable.mutate().setColorFilter(tintColor, PorterDuff.Mode.SRC_ATOP);
}
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
final Drawable thumb = seekBar.getThumb();
if (thumb != null) {
thumb.mutate().setColorFilter(tintColor, PorterDuff.Mode.SRC_ATOP);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment