Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom SeekBar thumb showing unwanted background

I've been trying to make a custom SeekBar. It's supposed to have round corners. Even the progress of SeekBar should have round corners at both sides. I don't need a thumb. Something like this.

Custom Seekbar with round corners

To achieve this, I've made a layer-list xml file, named custom_seekbar.xml as follows:

<?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 android:shape="rectangle">
            <corners android:radius="20dp" />
            <solid android:color="#F0E9DC" />
        </shape>
    </item>

    <item android:id="@android:id/secondaryProgress">
        <clip>
            <shape android:shape="rectangle">
                <corners android:radius="20dp" />
                <solid android:color="#F0E9DC" />
            </shape>
        </clip>
    </item>

    <item android:id="@android:id/progress">
        <clip>
            <shape android:shape="rectangle">
                <corners android:radius="20dp" />
                <solid android:color="#E38F71" />
            </shape>
        </clip>
    </item>

</layer-list>  

And to deal with the moving round corner, I thought of using a circle thumb with height equal to that of the SeekBar. Here's thumb.xml:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <size android:height="16dp"
        android:width="16dp"/>

    <corners android:radius="20dp"/>

    <solid android:color="#E38F71"/>

</shape>  

And I'm showing the SeekBar like this in my activity:

<SeekBar
        android:layout_width="250dp"
        android:layout_height="16dp"
        android:layout_centerInParent="true"
        android:progressDrawable="@drawable/custom_seekbar"
        android:thumb="@drawable/thumb" />  

The only problem is the thumb. It is not showing as expected. It has an unwanted background like this:

Custom Seekbar thumb with unwanted background

If I set a transparent thumb, the progress is not round anymore. I even tried using an Oval shape for thumb. Someone please tell me where I'm going wrong? Or if there's some other way I can achieve the desired results. Any help would be really appreciated.

like image 806
Anjani Avatar asked Oct 09 '15 12:10

Anjani


People also ask

How do I change my thumb SeekBar?

Just add android:thumbTint="@color/yourColor" in your seekbar.

How do I change the color of my SeekBar line?

If you are using default SeekBar provided by android Sdk then their is a simple way to change the color of that . just go to color. xml inside /res/values/colors. xml and change the colorAccent.

How can I make my own SeekBar?

Now go to the activity_main. xml create a layout and inside the layout add a SeekBar. Specify the height width of SeekBar and the max progress that you want to use set progress to 0. This will create a customized Seekbar inside activity_main.


1 Answers

adding android:splitTrack="false", will fix your problem. I would also use android:shape="oval", instead of rectangle with round corners, for your thumb.xml

like image 77
Blackbelt Avatar answered Sep 28 '22 00:09

Blackbelt