将SeekBar的进度颜色设置为透明

时间:2015-10-28 00:38:52

标签: 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

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

7 个答案:

答案 0 :(得分:5)

如何在Android中设置Seekbar的样式

在这里,您需要执行以下操作

第1步:

在drawable中,放入&#34; progress_bg.png&#34; (找附件)

第2步:

在drawable中,创建&#34; myprogessbar_style.xml&#34;,然后插入以下内容

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

第3步:

您的搜索栏

shoeboxImage

<强>结果

enter image description here

<强>附件

enter image description here

P.S。是的,它不是透明度,而是预期的结果

答案 1 :(得分:2)

这似乎有效:

<SeekBar
    ...
    android:progressTint="@android:color/transparent"
    ... />

答案 2 :(得分:0)

seekbar_background.xml

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

1px线形

答案 3 :(得分:0)

android:maxHeight =“3dp”将此添加到您提到搜索栏的布局xml中。如果要降低高度,可以更改dp

答案 4 :(得分:0)

这更容易解决。在您的seekbar_background.xml中:

而不是:

  android:color="FF555555"

尝试:

  android:color="@android:color/transparent"

答案 5 :(得分:0)

如果您想以编程方式进行:

 seekBar.progressTintList = ColorStateList.valueOf(Color.TRANSPARENT)

答案 6 :(得分:-1)

机器人:背景= “@机器人:彩色/透明”

这使我在Android Studio背景中的SeekBar变得透明。很直接。

相关问题