我有一个搜索栏,我需要在我的搜索栏的拇指上应用 getTemperatureColor函数,以便在搜索栏上选择拇指时从线性渐变中获取颜色,但我没有得到任何颜色这样做的想法。任何帮助都将受到高度赞赏。
我有点想到它会是这样的
seekbar.getThumb("我在这里需要帮助来应用getTemperatureColor()");
public class MainActivity extends AppCompatActivity {
private SeekBar seekBar = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
seekBar = (SeekBar)findViewById(R.id.seekBar);
final LinearGradient test = new LinearGradient(0.f, 0.f, 200.f, 380.f, new int[] { 0xFF0000FF, 0xFF00FF00, 0xFFFF0000},
null, Shader.TileMode.CLAMP);
RoundRectShape roundRectShape = new RoundRectShape(new float []{30f,30f,30f,30f,30f,30f,30f,30f},null,null);
shape = new ShapeDrawable(roundRectShape);
shape.getPaint().setShader(test);
seekBar.setProgressDrawable((Drawable) shape);
}
private int getTemperatureColor(float temperature) {
//Color range from 0 - 40 degC
float clipped = Math.max(0f, Math.min(40f, temperature));
float scaled = ((40f - clipped) / 40f) * 255f;
int blue = Math.round(scaled);
int red = 255 - blue;
return Color.rgb(red, 0, blue);
}
}
答案 0 :(得分:0)
有任何帮助吗?
seekBar.getThumb().setColorFilter(getTemperatureColor(30), PorterDuff.Mode.ADD);