10

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.

Remove this

Any help?

5 Answers 5

39

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));
4
  • Better solution than @GuyNoir 's solution above which requires an artificial "invisible drawable" to be created
    – Guy
    Jul 15, 2012 at 10:24
  • Just a note: you can't use #0000, but using @android:color/transparent works.
    – sidon
    Sep 10, 2012 at 15:38
  • But this removes the horizontal line also on holo light theme. I would like to keep that.
    – lalitm
    Mar 7, 2014 at 3:23
  • @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?
    – Pooks
    Mar 7, 2014 at 5:05
5

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.

3

Have you tried setBackgroundDrawable(null)?

4
  • I 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)
    – Kleptine
    Mar 17, 2010 at 1:27
  • and how I can restored to the initial after that ? tks
    – Paul
    Dec 17, 2012 at 16:31
  • 1
    @Paul: Try calling getBackground() first, saving the result somewhere, and later restoring it via setBackgroundDrawable(). Despite the non-parallel names, getBackground() returns a Drawable. Dec 17, 2012 at 16:37
  • unfortunately didn't worked... I've posted a clear question related to this issue here: stackoverflow.com/questions/14054548/… thanks.
    – Paul
    Dec 27, 2012 at 12:17
2

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>

0

create an xml file seekbar_progress.xml and place it in drawable folder.Here stripes is an image,take an image and place it in drawable folder.

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 xml file that is having seekbar code, take an image and store in drawable folder.here seekbar is an image.

    <SeekBar
             android:id="@+id/seekbar"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:background="@drawable/seekbar"
             android:progressDrawable="@drawable/seekbar_progress"/>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.