根据颜色更改为搜索栏值 [英] Changing color according to seek bar value

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

问题描述

我想根据搜索栏的值来改变颜色。我想的颜色出现​​在宽的范围。

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("");
          }
    });

任何想法?

推荐答案

如果您只需要明亮,饱和的色彩,使用 Col​​or.HSVToColor(),而不是设置R, G和B组分直接:

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

这code将设置颜色从红色开始,然后顺利地橙,黄,绿,蓝,洋红回冲更改为进度被更改 0 maxProgress

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

这篇关于根据颜色更改为搜索栏值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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