【发布时间】:2017-12-21 23:39:53
【问题描述】:
有没有办法可以删除 SeekBar android 小部件中的背景栏图像?
我只是希望它显示一个没有进度条的滑块。
有什么帮助吗?
【问题讨论】:
有没有办法可以删除 SeekBar android 小部件中的背景栏图像?
我只是希望它显示一个没有进度条的滑块。
有什么帮助吗?
【问题讨论】:
有一种更简单的方法,不需要创建新的可绘制对象。 只需在您的 xml 定义中设置以下内容
android:progressDrawable="@android:color/transparent"
或者如果你想在你的代码中这样做:
mySlider.setProgressDrawable(new ColorDrawable(android.R.color.transparent));
【讨论】:
好吧,我解决了我自己的问题。
要移除背景,你必须创建一个空白drawable并将其设置为progressDrawable:
satBar.setProgressDrawable(invisibleBackground);
将其设置为 null 似乎不起作用。
【讨论】:
【讨论】:
getBackground(),将结果保存在某处,然后通过setBackgroundDrawable() 恢复它。尽管名称不平行,getBackground() 返回 Drawable。
一种方法是将进度条的颜色更改为背景颜色。您必须使用自定义布局。
<SeekBar
android:layout_width="350px"
android:layout_height="25px"
android:layout_margin="30px"
android:layout_x="60px"
android:layout_y="185px"
android:id="@+id/seekbar"
android:progressDrawable="@drawable/myprogress"
/>
下面给出了一个自定义布局 - 玩弄颜色:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
<shape>
<corners android:radius="5dip" />
<gradient
android:startColor="#ff9d9e9d"
android:centerColor="#ff5a5d5a"
android:centerY="0.75"
android:endColor="#ff747674"
android:angle="270"
/>
</shape>
</item>
<item
android:id="@android:id/progress"
>
<clip>
<shape>
<corners
android:radius="5dip" />
<gradient
android:startColor="#9191FE"
android:centerColor="#9191FE"
android:centerY="0.75"
android:endColor="#9191FE"
android:angle="270" />
</shape>
</clip>
</item>
【讨论】:
创建一个xml文件seekbar_progress.xml并将其放在drawable文件夹中。这里stripes是一个图像,取一个图像并将它放在drawable文件夹中。
seekbar_progress.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<clip>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/stripes"
android:tileMode="repeat"
android:antialias="true"
android:dither="true"
android:filter="false"
android:gravity="left"
/>
</clip>
</item>
</layer-list>
现在在您的main xml 文件中,该文件包含搜索条码,拍摄一张图片并存储在drawable 文件夹中。这里的搜索条是一张图片。
<SeekBar
android:id="@+id/seekbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/seekbar"
android:progressDrawable="@drawable/seekbar_progress"/>
【讨论】: