我需要让SeekBar有3个位置,这些位置会改变每个位置的颜色,绿色,黄色和红色。现在我还在开始代码
<SeekBar
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginRight="10dp"
android:max="3"/>
seekbar [颜色]
答案 0 :(得分:0)
好的,我认为它应该对你有所帮助。我在colors.xml
中创建了:
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
<color name="colorGreen">#32CD32</color>
<color name="colorYellow">#D9D919</color>
<color name="colorRed">#cc0000</color>
并在MainActivity.java
我做了:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
seekBar = findViewById(R.id.seekBar);
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if(progress == 2) seekBar.setProgressDrawable(getDrawable(R.color.colorYellow));
if(progress == 3) seekBar.setProgressDrawable(getDrawable(R.color.colorRed));
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
}