Android Seekbar: How To Change The Color Of The Full Seekbar On Progress
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
Solution 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);
Post a Comment for "Android Seekbar: How To Change The Color Of The Full Seekbar On Progress"