android - 设置SeekBar的进度颜色为透明

标签 android seekbar

这是我想要完成的图片,其中没有进度颜色(透明),带有纯灰色背景栏:

seekbar

我试过了

android:progressTint="#00000000"

但这会将整个进度条(进度条和后退条)设置为透明。

我也试过:

android:progressDrawable="@drawable/customseekbar"

其中 customseekbar.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/seekbar_background" />

<item android:id="@android:id/progress">
    <clip android:drawable="@drawable/seekbar_background" />
</item>

和 seekbar_background.xml:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid
        android:color="#FF555555" />
</shape>

但后来我变得又胖又丑:

notwhatiwant

我在这里做错了什么?谢谢

最佳答案

如何在 Android 中设置 Seekbar 的样式

给你,你需要做以下事情

第 1 步:

在drawable中,放入“progress_bg.png”(见附件)

第 2 步:

在drawable中,创建“myprogessbar_style.xml”,并插入以下内容

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:id="@android:id/background"
          android:drawable="@drawable/progress_bg" />
    <item
        android:id="@android:id/secondaryProgress"
        >
        <scale
            android:drawable="@drawable/progress_bg"
            android:scaleWidth="100%"/>
    </item>
    <item
        android:id="@android:id/progress"
        android:drawable="@drawable/progress_bg"/>

</layer-list>

第 3 步:

你的搜索栏

<SeekBar
            android:id="@+id/seekBar1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:layout_margin="10dp"
            android:indeterminate="false"
            android:paddingLeft="15dp"
            android:paddingRight="15dp"
            android:progressDrawable="@drawable/myprogessbar_style"/>

结果

enter image description here

附件

enter image description here

附言是的,这不是透明度而是预期的结果

关于android - 设置SeekBar的进度颜色为透明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33380976/

相关文章:

android - 如何在警告对话框中放置搜索栏?

android - 带有自定义缩略图和分段文本的 SeekBar

android - 从服务更新搜索栏

android - 如何根据标题、描述或纬度或经度在 map 上查找标记

java - "Error while waiting for device: adb connection not available, or was terminated"?

Android & Rx Java 2 : get notified when object changes

java - 与 FLAG_LAYOUT_NO_LIMITS 相反

java - 在 android while 循环中使用 URL get 发送数据

android - 如何在vitamio中实现拖动seekbar时即时seek

java - 如何在 Android 上使用两个或多个搜索栏