Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can you dynamically update the color of a SeekBar?

Tags:

android

I would like to have the color of the progress bar (specifically the secondary progress that is updated with setSecondaryProgress) to change dynamically at runtime when it crosses a certain point.

I am already able to substitute my own drawable into the bar during my Activity's onCreate function (changing color from yellow to green) by calling setProgressDrawable and substituting a resource I've copied from the default Android version of a horizontal progress (SDK/platforms/android-2.1/data/res/drawable/progress_horizontal.xml). However, updating this at runtime (yes, from the UI thread via an AsyncTask) causes the entire progress bar except for the thumbtab to go black or transparent.

like image 699
PseudoNoise Avatar asked Feb 23 '10 02:02

PseudoNoise


People also ask

How do I change the color of my SeekBar track?

If you are using default SeekBar provided by android Sdk then their is a simple way to change the color of that . just go to color. xml inside /res/values/colors. xml and change the colorAccent.

How do I change the color of my SeekBar Android?

The user can touch the thumb and drag left or right to set the current progress level or use the arrow keys .

How do I SeekBar progress?

You are looking for the method getProgress() of the ProgressBar class as SeekBar is a subclass of ProgressBar . So basically it would be something like that. int value = seekBar. getProgress();

How do I change the width of SeekBar?

You can use the Slider provided by the Material Components Library. Use the app:trackHeight="xxdp" (the default value is 4dp ) to change the height of the track bar.


1 Answers

I think this is what you are looking for

enter image description here

enter image description here

enter image description here

This can be achived by creating custom drwables for background and progress of seak bar See this link for sample code.

Pls see the below links also http://javatechig.com/android/android-seekbar-example/

Change the color of a seekbar on onProgressChanged

like image 98
chandan Avatar answered Nov 15 '22 03:11

chandan