我有两个问题:
1)如何将进度条(路径)的颜色从黄色(默认颜色)更改为白色。我的意思是,当我滑动拇指时,它会将从灰色到黄色的已经滑过的部分变色。我希望进度条保持灰色或白色,只有拇指移动而没有颜色变化。
2)如何将进度条的拇指从矩形更改为圆形/球形/圆形。
任何指针都将不胜感激。
我有两个问题:
1)如何将进度条(路径)的颜色从黄色(默认颜色)更改为白色。我的意思是,当我滑动拇指时,它会将从灰色到黄色的已经滑过的部分变色。我希望进度条保持灰色或白色,只有拇指移动而没有颜色变化。
2)如何将进度条的拇指从矩形更改为圆形/球形/圆形。
任何指针都将不胜感激。
我想为那些刚接触该系统的人补充上面的答案,
缺失的xml文件(background_fill、progress_fill和progress)可以像这样设置一个渐变红色:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@android:id/background"
android:drawable="@drawable/background_fill" />
<item android:id="@android:id/progress">
<clip android:drawable="@drawable/progress_fill" />
</item>
</layer-list>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:startColor="#FF555555"
android:centerColor="#FF555555"
android:endColor="#FF555555"
android:angle="90" />
<corners android:radius="5px" />
<stroke
android:width="2dp"
android:color="#50999999" />
<stroke
android:width="1dp"
android:color="#70555555" />
</shape>
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:startColor="#FF470000"
android:centerColor="#FFB80000"
android:endColor="#FFFF4400"
android:angle="180" />
<corners android:radius="5px" />
<stroke
android:width="2dp"
android:color="#50999999" />
<stroke
android:width="1dp"
android:color="#70555555" />
</shape>
我没有完成对 android:thumb 的实现,所以滑块仍然是原来的。
因此,我们只需从定义 seekbar 的布局 xml 中再次删除此行即可。
android:thumb="@drawable/thumb"
你应该设置SeekBar的XML属性:
<SeekBar
....
android:progressDrawable="@drawable/progress"
android:thumb="@drawable/thumb"
....
/>
进展大致如下:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background"
android:drawable="@drawable/background_fill" />
<item android:id="@android:id/progress">
<clip android:drawable="@drawable/progress_fill" />
</item>
</layer-list>
并且thumb是
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/thumb_fill" />
</selector>
由于默认情况下SeekBar
使用colorAccent
,您可以创建一个新样式,将自定义颜色作为colorAccent
,然后使用theme
属性将其应用于SeekBar。
<SeekBar>
.
.
android:theme="@style/MySeekBarTheme"
.
</SeekBar>
在 @style 属性中:
<style name="MySeekBarTheme" parent="Widget.AppCompat.SeekBar" >
<item name="colorAccent">#ffff00</item>
</style>
seekBar.getProgressDrawable().setColorFilter(Color.RED, PorterDuff.Mode.SRC_IN);
seekBar.getThumb().setColorFilter(Color.RED, PorterDuff.Mode.SRC_IN);
您只需要从API级别21开始添加色彩。
将这些属性添加到SeekBar元素中:
android:progressTint="@android:color/white" android:thumbTint="@android:color/white"
最终结果:
<SeekBar
android:id="@+id/is"
android:layout_width="match_parent"
android:max="100"
android:progressTint="@android:color/white"
android:thumbTint="@android:color/white"/>
1. 创建一个可绘制的XML文件: 将其命名为:progress_drawable
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
<stroke android:width="1dp" android:color="#fff"/>
</shape>
2. 将其分配给 Seekbar
<SeekBar
android:id="@+id/slider_1"
android:progressDrawable="@drawable/progress_drawable"
android:layout_width="180dp"
android:layout_height="32dp"
android:layout_gravity="center"
android:rotation="270" />
只需更改您的样式的强调颜色
<style name="TickMarkSeekBar" parent="Theme.KefTheme">
<item name="tickMark">@drawable/tickmark</item>
<item name="thumbTint">@android:color/white</item>
<item name="colorAccent">@android:color/white</item>
</style>