如何更改SeekBar的背景?

4
我希望将SeekBar的背景颜色从黄色(默认)更改为我选择的颜色,但我只找到了更改SeekBar周围黑色区域颜色的方法。有谁可以帮助我吗?

请查看此链接:[https://dev59.com/L3A75IYBdhLWcg3wFE6b][1] - AliSh
1个回答

9

xmls(background_fill,progress_fill和progress)可能如下所示,呈渐变红色。

进度xml

  <?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>

背景填充XML

<?xml version="1.0" encoding="UTF-8"?>
                <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

 <?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"

for more info see this link


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接