-1

I need to make SeekBar with 3 positions that will change color on each of them, green, yellow and red. For now i am still on beginning of code

<SeekBar
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:layout_marginRight="10dp"
    android:max="3"/>

seekbar[colors]

1 Answers1

0

Ok, I think it should helps you. I created in colors.xml:

<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
<color name="colorGreen">#32CD32</color>
<color name="colorYellow">#D9D919</color>
<color name="colorRed">#cc0000</color>

and in MainActivity.java I did:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    seekBar = findViewById(R.id.seekBar);
    seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            if(progress == 2) seekBar.setProgressDrawable(getDrawable(R.color.colorYellow));
            if(progress == 3) seekBar.setProgressDrawable(getDrawable(R.color.colorRed));


        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {

        }
    });
}
newbieHere
  • 276
  • 2
  • 15
  • This is also good,it works also, I will probably use this, but do you think that pointer on seekbar can change the colors, instead progress line on seekbar? – Bojan Naneski May 12 '18 at 21:23
  • Yeah I think it's possible to change, but I'm not sure how to do it cause i've never did it. I know, that in xml color thumb u can set by android:thumbTint="@color/colorRed" . Unfortunately I don't know how to make a color changer like for seek bar in java. – newbieHere May 13 '18 at 20:31