将SeekBar进度颜色设置为透明

问题描述 投票:12回答:6

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

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
6个回答
5
投票

如何在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

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


2
投票

这似乎有效:

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

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线形


0
投票

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


0
投票

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

代替:

  android:color="FF555555"

尝试:

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

-1
投票

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

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

© www.soinside.com 2019 - 2024. All rights reserved.