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.
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:
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.
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