-1

I have a SeekBar in one of my activites in my app.

That seekbar gives me an importance of the object I create. Importance can be 0,1 or 2.

I'd like to dinamically change the background color of my SeekBar when I'm using it. How can I do that ?

Here are the colors I'd like to use :

Importance 0 : "#ff8080"

Importance 1 :"#ff0000"

Importance 2 :"#4d0000"

Thank you for your help, and tell me if you need more code !

  BarreImportance.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int i, boolean b) {

            if(i==0)
            { //it does not accept my colors..
                BarreImportance.getProgressDrawable().setColorFilter(Color.parseColor("#ff8080"));
            }
            if(i==1)
            {
      //it changes the whole background, not what  I want...          BarreImportance.setBackgroundColor(Color.parseColor("#ff0000"));

        }
David
  • 221
  • 3
  • 13
  • You are setting a color filter in a wrong way. First, call it on your `seekBar` object. Second, try something like this: `setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP);` – Robert K. Jun 05 '17 at 13:32
  • oh thank you ! but is it possible to also change the color of the circle ? Because if importance is 0 i'd like to have the color at least so the user can recognises after.. – David Jun 05 '17 at 13:44
  • seekBar.getThumb().setColorFilter(..) – Robert K. Jun 05 '17 at 13:47
  • I'm using API 14... and minimum for getThumb is 16.. any idea ? – David Jun 05 '17 at 14:02
  • Check this answer https://stackoverflow.com/questions/18622120/detecting-thumb-position-in-seekbar-prior-to-api-version-16 – Robert K. Jun 05 '17 at 14:50

1 Answers1

1

You need to use OnSeekBarChangeListener's onProgressChanged callback and change the color from inside there like this: mySeekBar.getProgressDrawable().setColorFilter(..) and mySeekBar.getThumb().setColorFilter(..)

Robert K.
  • 1,043
  • 1
  • 8
  • 20