I am trying to change color according to value of seek bar. I'd like colors to appear in wide range.
Here is what I tried, but it doesn't give me colors I want:
seekBarColor.setOnSeekBarChangeListener( new OnSeekBarChangeListener() {
int progress = 0;
@Override
public void onProgressChanged(SeekBar seekBar, int progresValue, boolean fromUser) {
progress = progresValue;
int lower = Color.argb(0xFF,progress*0x10000, progress*0x100, progress)+0xff000000;
color.setBackgroundColor(lower);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
db.updateColor("");
}
});
Any ideas?
If you need only bright, saturated colors, use Color.HSVToColor()
instead of setting R, G and B components directly:
float[] hsvColor = {0, 1, 1};
// generate only hue component in range [0, 360),
// leaving saturation and brightness maximum possible
hsvColor[0] = 360f * progress / maxProgress;
view.setBackgroundColor(Color.HSVToColor(hsvColor));
This code will set color starting from red, then change smoothly to orange, yellow, green, blue and magenta back to red as progress
is changing from 0
to maxProgress
You have to pass 0-255 values to Color.argb(int,int,int,int)
method.
This might work?
Color.argb(0xFF, progress, progress, progress) //will return some gray color based on progress.
You might have to scale your progress value based on the min and max value.
For example if you have progress 0-100
then you should calculate your color values with progress * 255 / 100
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With