Android Remove SeekBar Background

2020-08-20 11:35发布

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条回答
smile是对你的礼貌
2楼-- · 2020-08-20 11:43
在下西门庆
3楼-- · 2020-08-20 11:45

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.

查看更多
Fickle 薄情
4楼-- · 2020-08-20 11:52

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"/>
查看更多
等我变得足够好
5楼-- · 2020-08-20 11:54

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));
查看更多
迷人小祖宗
6楼-- · 2020-08-20 12:00

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>

查看更多
登录 后发表回答