Android Remove SeekBar Background
13,863
Solution 1
Well I solved my own problem.
To remove the background, you have to create a blank drawable and set it to the progressDrawable:
satBar.setProgressDrawable(invisibleBackground);
Setting it to null doesn't seem to work.
Solution 2
There is a simpler way that doesn't require creating a new drawable. Simply set the following in your xml definition
android:progressDrawable="@android:color/transparent"
Or if you want to do it in your code:
mySlider.setProgressDrawable(new ColorDrawable(android.R.color.transparent));
Solution 3
Have you tried setBackgroundDrawable(null)
?
Solution 4
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>
Author by
Kleptine
Updated on June 09, 2022Comments
-
Kleptine almost 2 years
Is there a way I can remove the background bar image in the SeekBar android widget?
I just want it to show a slider with no progress bar behind it.
Any help?
-
Kleptine about 14 yearsI have. The background drawable is actually behind the bar itself. I need a way to delete the bar (and also change the image of the slider)
-
Guy almost 12 yearsBetter solution than @GuyNoir 's solution above which requires an artificial "invisible drawable" to be created
-
sidon over 11 yearsJust a note: you can't use #0000, but using @android:color/transparent works.
-
Paul over 11 yearsand how I can restored to the initial after that ? tks
-
CommonsWare over 11 years@Paul: Try calling
getBackground()
first, saving the result somewhere, and later restoring it viasetBackgroundDrawable()
. Despite the non-parallel names,getBackground()
returns aDrawable
. -
Paul over 11 yearsunfortunately didn't worked... I've posted a clear question related to this issue here: stackoverflow.com/questions/14054548/… thanks.
-
lalitm about 10 yearsBut this removes the horizontal line also on holo light theme. I would like to keep that.
-
Pooks about 10 years@lalitm I'm not sure what you mean. The OP wants to remove the bar and keep only the tab. Isn't the horizontal line the equivalent of the bar in holo light? I guess the best thing to do would be to post a new question and include an image of what you want to do. Or maybe the answer from CommonsWare below is what you want to do?