Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change seek bar progress colour according to its progress?

I want to create a custom seekbar, whose progress bar's colour change between red and blue as the user changes the progress of the bar.

I have tried it but its only changing the background colour not the progress bar color.

seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

            public void onStopTrackingTouch(SeekBar seekBar) {
                // TODO Auto-generated method stub

            }

            public void onStartTrackingTouch(SeekBar seekBar) {
                // TODO Auto-generated method stub

            }

            public void onProgressChanged(SeekBar seekBar, int progress,
                    boolean fromUser) {


                seekBar.setBackgroundColor(Color.RED + progress);

            }
        });
like image 637
Adil Bhatty Avatar asked Dec 23 '11 11:12

Adil Bhatty


People also ask

How do I change the color of my progress indicator?

To change the circular progress indicator color globally, you can use the ColorScheme class. It's a group of 25 colors based on the Material 3 design. Using the ColorScheme class you can define the colors for your app.

How do you change how much of the progress bar is filled in?

You need to call setLevel on the ClipDrawable. It takes a value from 0 to 10000. So, progress. setLevel(2500) would be 25% full.

How do I customize SeekBar?

Now go to the activity_main. xml create a layout and inside the layout add a SeekBar. Specify the height width of SeekBar and the max progress that you want to use set progress to 0. This will create a customized Seekbar inside activity_main.


2 Answers

There are a lot of way to do this, I'll tell the simple way. You can set the color of progressBackground like this:

seekBar.getProgressDrawable().setColorFilter("<Color you wish>", PorterDuff.Mode.MULTIPLY);

If your api level 21, you can use getProgressBackgroundTintList or getProgressBackgroundTintMode().

like image 175
uiltonsantos Avatar answered Oct 03 '22 10:10

uiltonsantos


use custom seek bar for that requirement see following link's

  1. http://www.mokasocial.com/2011/02/create-a-custom-styled-ui-slider-seekbar-in-android/

  2. Seek bar, change path color from yellow to white

like image 30
RajaReddy PolamReddy Avatar answered Oct 03 '22 09:10

RajaReddy PolamReddy