Home » Android » java – Android Remove SeekBar Background

java – Android Remove SeekBar Background

Posted by: admin May 14, 2020 Leave a comment

Questions:

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?

How to&Answers:

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));

Answer:

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.

Answer:

Have you tried setBackgroundDrawable(null)?

Answer:

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>

Answer:

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"/>