Android的搜索栏:如何更改进度全面搜索栏的颜色 [英] Android SeekBar: How to change the color of the full seekbar on progress

查看:240
本文介绍了Android的搜索栏:如何更改进度全面搜索栏的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将绿色时进度为0,搜索栏。
当进度达到50,然后再慢慢进步时为100变为红色的颜色会逐渐变为黄

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.

可能有人请帮忙吗?

感谢。

推荐答案

试试这个,你需要改变HSV阵列来满足您的需求。

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);

这篇关于Android的搜索栏:如何更改进度全面搜索栏的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆