Android 自定义 SeekBar 在缓冲时更改进度颜色和背景颜色
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21473442/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Custom SeekBar which changes both Progress Color and Background Color while buffering
提问by beerBear
I want to build a custom SeekBar which has a secondary progress bar but by default is from end to end and shows progress for buffered data.
Think of it as the seekbar provided by most online video players e.g. youtube. So all in all we have the default seekbar, its default progress bar and a secondary progress bar which fills a color irrespective of the main progress/user's drag of the seekbar's notch and just dependent on buffered data.
我想构建一个自定义的 SeekBar,它有一个辅助进度条,但默认情况下是从头到尾显示缓冲数据的进度。
将其视为大多数在线视频播放器(例如 youtube)提供的搜索栏。所以总而言之,我们有默认的搜索栏、它的默认进度栏和一个辅助进度栏,它填充颜色而不管主要进度/用户对搜索栏槽口的拖动,并且只依赖于缓冲数据。
Till now I just have the normal seekbar and it changes color on user's drag/set progress.
Could someone please help with this?
到目前为止,我只有普通的搜索栏,它会根据用户的拖动/设置进度改变颜色。
有人可以帮忙吗?
My code so far:
seekbar_progress.xml
到目前为止我的代码:
seekbar_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/progress_background_fill"/>
<item android:id="@android:id/progress">
<clip android:drawable="@drawable/progress_fill" />
</item>
</layer-list>
progress_fill.xml
progress_fill.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<gradient
android:angle="180"
android:centerColor="#FFB80000"
android:endColor="#FFFF4400"
android:startColor="#FF470000" />
<corners android:radius="5px" />
<stroke
android:width="2dp"
android:color="#50999999" />
<stroke
android:width="1dp"
android:color="#70555555" />
</shape>
progress_background_fill.xml
progress_background_fill.xml
<gradient
android:angle="90"
android:centerColor="#FF555555"
android:endColor="#FF555555"
android:startColor="#FF555555" />
<corners android:radius="5px" />
<stroke
android:width="2dp"
android:color="#50999999" />
<stroke
android:width="1dp"
android:color="#70555555" />
applying these xml(s) like this:
像这样应用这些 xml(s):
<SeekBar
android:id="@+id/seek_hist_timeline"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:progressDrawable="@drawable/seekbar_progress" />
回答by dandc87
Add another layer to your layer-list drawable with the id android:id/secondaryProgress
使用 id 将另一个图层添加到您的图层列表 drawable android:id/secondaryProgress
Refer to this answer: https://stackoverflow.com/a/2021119/2951003
回答by Nevil Ghelani
Here's your answer. Just add two lines in seekbar tag in xml
这是你的答案。只需在xml中的seekbar标签中添加两行
<SeekBar
android:progressTint="@color/black"
android:thumbTint="@color/black"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
change color accordingly.
相应地改变颜色。