How to remove the default indicator icon of a seekbar [android] which has been set a custom progress drawable

Itapu Vinay picture Itapu Vinay · Sep 25, 2015 · Viewed 8.2k times · Source

Please find the below screenshot of a custom seekbar I am trying to achieve. enter image description here

I am very much close in building the seekbar as shown above (without the images below the seekbar). Below is the screenshot of what I have done.

enter image description here

Problem:

As you can see in the second screenshot, there is an icon after the progress indicator bar in the seekbar. I have been trying to get rid of that but apparently not successful in doing that. Any suggestions/ideas on how to remove that icon would be of great help. Thanks.

SeekBar Layout XML

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.application.todo.activityTransition.activities.SeekBarActivity">

<TextView
    android:id="@+id/painLevelText"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:padding="10dp"
    android:text="@string/painLevelText" />

<LinearLayout
    android:id="@+id/radIoGroupLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/painLevelText"
    android:orientation="vertical">

    <RadioGroup
        android:id="@+id/seekBarRadioGroup"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:weightSum="10">

        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1" />

        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1" />

        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1" />

        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1" />

        <RadioButton
            android:id="@+id/defaultSelection"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1" />

        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1" />

        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1" />

        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1" />

        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1" />

        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1" />
    </RadioGroup>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"
        android:orientation="horizontal"
        android:weightSum="10">

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:text="1" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:text="2" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:text="3" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:text="4" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:text="5" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:text="6" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:text="7" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:text="8" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:text="9" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:text="10" />

    </LinearLayout>

</LinearLayout>

<RelativeLayout
    android:id="@+id/seekBarLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/radIoGroupLayout"
    android:background="@drawable/seekbar_layout_background">

    <SeekBar
        android:id="@+id/seekBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:max="10"
        android:progress="5"
        android:progressDrawable="@drawable/custom_seek_bar" />

    <TextView
        android:id="@+id/seekBarProgressValue"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:gravity="center"
        android:padding="10dp"
        android:textColor="#FFF"
        android:textSize="15sp" />
</RelativeLayout>


</RelativeLayout>

Custom Drawable file used for seekbar

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/progress">
    <clip>
        <shape android:shape="rectangle">
            <size
                android:width="12dp"
                android:height="12dp" />
            <corners android:radius="15dp" />

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

            <gradient
                android:angle="270"
                android:centerColor="#FF8D1E"
                android:endColor="#FF971F"
                android:startColor="#FF971F" />
        </shape>
    </clip>
</item>
</layer-list>

Please find my answer under answer section

Answer

Itapu Vinay picture Itapu Vinay · Sep 25, 2015

This link was helpful in achieving the desired result. But I found an issue while using the below line of code

seekBar.getThumb().mutate().setAlpha(0);

It does remove the thumb at the end but the progress indicator is chopped when we select "10" from the radiogroup. Below is the related image.

enter image description here

But when I used this XML tag for seekbar in my layout, it was working as expected.

android:thumb="@null"

Image

enter image description here

Not sure if that was the right approach but it did the trick.