问题
i would like to a seek bar which is colored green when progress is at 0. The colour slowly changes to yellow when the progress reaches 50 and then again slowly changes to red when progress is 100.
I am able to do this for the progress portion of the seekbar.
But I would like to have the full colour of the seek bar change, not just the progress portion.
Could someone please help?
Thanks.
回答1:
try this, you need to change hsv array to meet your needs
final ProgressBar pb = new ProgressBar(this, null, android.R.attr.progressBarStyleHorizontal);
LayerDrawable ld = (LayerDrawable) pb.getProgressDrawable();
final Drawable progressDrawable = ld.findDrawableByLayerId(android.R.id.progress);
OnTouchListener l = new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
int progress = (int) (event.getX() * 100 / pb.getWidth());
float[] hsv = {
event.getX() * 360 / pb.getWidth(), 1, 1
};
int color = Color.HSVToColor(hsv);
progressDrawable.setColorFilter(color, Mode.SRC);
pb.setProgress(progress);
return true;
}
};
pb.setOnTouchListener(l);
LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, 32);
setContentView(pb, lp);
来源:https://stackoverflow.com/questions/20452083/android-seekbar-how-to-change-the-color-of-the-full-seekbar-on-progress