0

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

Fishingfon
  • 1,034
  • 3
  • 19
  • 33
  • 1
    like this? http://stackoverflow.com/q/9837843/2001247 – ElDuderino Dec 12 '14 at 13:40
  • Hi, I tried what was said in that link, but unfortuantely, it didnt work. After much trial and error however, i did manage to find a way to change the colour of the seekbar. Thanks anyway for your help, its much appreciated. Corey B :) – Fishingfon Dec 13 '14 at 14:03

1 Answers1

4

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);

}
Dilroop Singh
  • 544
  • 6
  • 16