Created
December 1, 2016 11:24
-
-
Save ahmedre/4387b219c11a145ecdbbf40b2d63de01 to your computer and use it in GitHub Desktop.
Tint a SeekBar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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