【问题标题】:Custom SeekBar which changes both Progress Color and Background Color while buffering自定义 SeekBar 在缓冲时同时更改进度颜色和背景颜色
【发布时间】:2014-01-31 05:59:08
【问题描述】:


我想构建一个自定义的 SeekBar,它有一个辅助进度条,但默认情况下是端到端的,并显示缓冲数据的进度。

将其视为大多数在线视频播放器提供的搜索栏,例如YouTube。所以总而言之,我们有默认的搜索栏,它的默认进度条和一个填充颜色的辅助进度条,无论主要进度/用户拖动搜索栏的槽口如何,并且仅依赖于缓冲数据。

到目前为止,我只有正常的搜索栏,它会随着用户的拖动/设置进度而改变颜色。
有人可以帮忙吗?

到目前为止我的代码:
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

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

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

像这样应用这些 xml(s):

<SeekBar 
            android:id="@+id/seek_hist_timeline"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:progressDrawable="@drawable/seekbar_progress" />

【问题讨论】:

    标签: android colors seekbar android-styles


    【解决方案1】:

    将另一个图层添加到您的图层列表可绘制对象中,id 为 android:id/secondaryProgress

    参考这个答案:https://stackoverflow.com/a/2021119/2951003

    【讨论】:

    • 一定要把android:id/secondaryProgress放在图层列表的背景和进度ID之间
    【解决方案2】:

    这是你的答案。 只需在 xml 的 seekbar 标签中添加两行

    <SeekBar
        android:progressTint="@color/black"
        android:thumbTint="@color/black"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
    

    相应地改变颜色。

    【讨论】:

    • 我喜欢这个。谢谢!
    猜你喜欢
    • 2013-06-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-25
    相关资源
    最近更新 更多