java Android 移除 SeekBar 背景
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2459326/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android Remove SeekBar Background
提问by Kleptine
Is there a way I can remove the background bar image in the SeekBar android widget?
有没有办法可以删除 SeekBar android 小部件中的背景栏图像?
I just want it to show a slider with no progress bar behind it.
我只是想让它显示一个滑块,后面没有进度条。


Any help?
有什么帮助吗?
采纳答案by Kleptine
Well I solved my own problem.
好吧,我解决了我自己的问题。
To remove the background, you have to create a blank drawable and set it to the progressDrawable:
要移除背景,您必须创建一个空白的 drawable 并将其设置为 progressDrawable:
satBar.setProgressDrawable(invisibleBackground);
Setting it to null doesn't seem to work.
将其设置为 null 似乎不起作用。
回答by Pooks
There is a simpler way that doesn't require creating a new drawable. Simply set the following in your xml definition
有一种更简单的方法不需要创建新的可绘制对象。只需在您的 xml 定义中设置以下内容
android:progressDrawable="@android:color/transparent"
Or if you want to do it in your code:
或者,如果您想在代码中执行此操作:
mySlider.setProgressDrawable(new ColorDrawable(android.R.color.transparent));
回答by CommonsWare
Have you tried setBackgroundDrawable(null)?
回答by ahsan
One way to do this would be to change the color of the progress bar to the background color. You have to use a custom layout.
一种方法是将进度条的颜色更改为背景颜色。您必须使用自定义布局。
<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"
/>
A custom layout is given below - play around with the colors :
下面给出了自定义布局 - 使用颜色:
<?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>
回答by swathi
create an xml file seekbar_progress.xmland place it in drawablefolder.Here stripes is an image,take an image and place it in drawablefolder.
创建一个xml文件seekbar_progress.xml并将其drawable放置在drawable文件夹中。这里的条纹是一个图像,拍摄一个图像并将其放置在文件夹中。
seekbar_progress.xml
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>
Now in your main xmlfile that is having seekbar code, take an image and store in drawablefolder.here seekbar is an image.
现在,在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"/>

