How do I change the SeekBar color in Android? (Program)

I made an equalizer to go with my app, but I'm not sure how I can change the thumb pointer and progress color. It is still pink by default, which doesn't fit my app aesthetic.

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

      

+3


source to share


5 answers


To change the color of the palette Seekbar

, create a new style instyle.xml

<style name="SeekBarColor"
  parent="Widget.AppCompat.SeekBar"> 
  <item name="colorAccent">@color/your_color</item> 
</style>

      

Finally, in the layout:

<SeekBar
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:theme="@style/SeekBarColor" />

      

To change execution color Seekbar

use this in Java Class.



seekBar.getProgressDrawable().setColorFilter("yourcolor", PorterDuff.Mode.MULTIPLY);

      

Both will work for API> 16.

Edit

Change the color of the SeekBar icon using Java code.

 seekBar.getProgressDrawable().setColorFilter(getResources().getCo‌​lor(R.color.your_color‌​), PorterDuff.Mode.SRC_ATOP);

      

+3


source


You need to call you, for example, a search engine

SeekBar newSeek = new SeekBar(this, null, R.style.YOUR_NEW_STYLE);

      



where YOUR_NEW_STYLE

will define the colors Seekbar

you want.

0


source


try this:

seekBar.getProgressDrawable().setColorFilter(getResources().getColor(R.color.mcolor), PorterDuff.Mode.MULTIPLY);

      

0


source


It's a good idea when using a style, it doesn't provide much flexibility, especially if you want to assign 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);

0


source


    //seekBar.setBackgroundColor(Color.DKGRAY);
    //seekBar.setDrawingCacheBackgroundColor(Color.DKGRAY);

      

There are several views in the Android SDK (ProgressBar is another example) where you need to change the color using graphical color filters instead of changing the Background / Foreground background color.

Find a .setColorFilter()

method, put your original color into it with some PorterDuff filter for example .Mode.MULTIPLY

(whichever filter mode you like best) and there you go.

Example:

seekBar.setColorFilter(new PorterDuffColorFilter(srcColor,PorterDuff.Mode.MULTIPLY));

      

-1


source







All Articles