Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android ProgressBar.setProgressDrawable only works once?

In a color picker, I have 3 SeekBars for Hue, Saturation, and Value. Calling setProgressDrawable on these SeekBars only works once -- at initialization from onCreate. When the user updates the Hue SeekBar, I want to call setProgressDrawable for the Saturation and Value SeekBars, to show the user their color choices for the new Hue.

But all calls to setProgressDrawable (after the initial ones from onCreate) cause the SeekBar to be blanked.

How can I update the background gradient of my SeekBars based upon user input?

like image 365
Chuck Avatar asked May 10 '10 19:05

Chuck


1 Answers

What I found out is that the drawable doesn't know it's size when setprogressdrawable is called. When it is initially set up, it does know it's size. This means there is a new drawable set to the seekbar, but the size of the drawable is 0, you won't see anything.

The solution is to first get the bounds of the current drawable, then set the new drawable and finally set the bounds again:

Rect bounds = mySeekBar.getProgressDrawable().getBounds();
mySeekBar.setProgressDrawable(newSeekBarBackground);
mySeekBar.getProgressDrawable().setBounds(bounds);
like image 163
toneffectory Avatar answered Sep 18 '22 01:09

toneffectory