Reputation: 1034
I have tried to find a solution to this problem, but nothing i try seems to give the effect i want.
In my app, i have a SeekBar, that i want to change the colour of to match the current file being played (user can set different colours for different files). My problem is that i am not able to find a way of setting the progress and thumb colour of the seekbar at runtime, as i dont know what colours will be used until the app runs, so i cant create XML drawables for each colour.
If someone knows of a way of changing the colour of the progress and thumb of the SeekBar at runtime, I would much appreciate their help.
Thanks, Corey B
Upvotes: 0
Views: 2025
Reputation: 544
For those who have same problem. From above code i understand you want to change colour of SeekBar i had same problem , after lot of search i made method of my own.
public void changeSeekbarColor(SeekBar s,int colorp,int colors,int color b)
{
PorterDuff.Mode mMode = PorterDuff.Mode.SRC_ATOP;
LayerDrawable layerDrawable = (LayerDrawable) s.getProgressDrawable();
Drawable progress = (Drawable) layerDrawable.findDrawableByLayerId(android.R.id.progress);
Drawable secondary = (Drawable) layerDrawable.findDrawableByLayerId(android.R.id.secondaryProgress);
Drawable background = (Drawable) layerDrawable.findDrawableByLayerId(android.R.id.background);
Drawable th = s.getThumb();
// Setting colors
progress.setColorFilter(colorp,mMode);
secondary.setColorFilter(colors,mMode);
background.setColorFilter(colorb, mMode);
th.setColorFilter(colorp,mMode);
// Applying Tinted Drawables
layerDrawable.setDrawableByLayerId(android.R.id.progress, progress);
layerDrawable.setDrawableByLayerId(android.R.id.secondaryProgress, secondary);
layerDrawable.setDrawableByLayerId(android.R.id.background, background);
}
Upvotes: 4