I made an equalizer to go with my app but I am not sure how I can change the seekbar's thumb and progress color. It seems to be pink by default and that doesn't fit my app's aesthetics.
SeekBar seekBar = new SeekBar(this);
seekBar.setId(i);
seekBar.setLayoutParams(layoutParams);
seekBar.setMax(upperEqualizerBandLevel - lowerEqualizerBandLevel);
seekBar.setProgress(mEqualizer.getBandLevel(equalizerBandIndex));
//seekBar.setBackgroundColor(Color.DKGRAY);
//seekBar.setDrawingCacheBackgroundColor(Color.DKGRAY);
To change the color of the
Seekbar
thumb, create a new style instyle.xml
Finally in the layout:
To change the
Seekbar
progress color, use this in Java Class.Both these will work for API>16.
Edit
To change SeekBar thumb color by Java code.
While using a style is a good idea, it does not provide much flexibility specially if you want to assign the colors programmatically I suggest:
//for the progress seekBar.getProgressDrawable().setColorFilter(mThemeColor,PorterDuff.Mode.SRC_ATOP); //for the thumb handle seekBar.getThumb().setColorFilter(mThemeColor, PorterDuff.Mode.SRC_ATOP);
You can change seekbar thumb and progress colors for programmatically like this:
There are few Views in Android SDK (ProgressBar is another example) in which you have to change colour using graphical color filters, instead of changing Background / Foreground source colour.
Find
.setColorFilter()
method, supply your source colour into it with some PorterDuff filter, like.Mode.MULTIPLY
(depending on what filter mode you like best) and there you go.Example:
You can easily change it via code,
For example:
or
Hoping that it will be helpfull for someone in future.
Just a little more peachy answer