1

If I set draw "progress drawable" in SeekBar I get bgdraw in all progress line. How can I set draw from start to thumb position?

Onur A.
  • 3,007
  • 3
  • 22
  • 37
user2542715
  • 185
  • 2
  • 4
  • 10

3 Answers3

8

you can use this way:

make a custom file in drawable folder....

<?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>
        <gradient 
                android:startColor="#00000000"
                android:centerColor="#00000000"
                android:centerX="1"
                android:endColor="#00000000"
                android:angle="0"
        />
    </shape>
</item>
<item android:id="@android:id/secondaryProgress" >
    <clip android:clipOrientation="horizontal" android:gravity="left" >
        <shape>
            <gradient
                    android:startColor="@color/blue"
                    android:centerColor="@color/blue"
                    android:centerX="0.75"
                    android:endColor="@color/blue"
                    android:angle="0"
            />
        </shape>
    </clip>
</item>

<item android:id="@android:id/progress" >
    <clip android:clipOrientation="horizontal" android:gravity="left" >
        <shape>
            <gradient
                    android:startColor="@color/blue"
                    android:centerColor="@color/blue"
                    android:centerX="0.75"
                    android:endColor="@color/blue"
                    android:angle="0"
            />
        </shape>
    </clip>
</item>

and after that set this custom file in your xml file:

  <SeekBar
            android:id="@+id/skProgress"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_marginTop="10dp"
            android:background="@android:color/white"
            android:gravity="center|center_vertical"
            android:progressDrawable="@drawable/progress_Ever" // here whatever name your custom file in drawable...set to here
  />
Piyush
  • 18,895
  • 5
  • 32
  • 63
4

In your xml

<SeekBar
                android:id="@+id/skProgress"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:layout_marginTop="10dp"
                android:background="@android:color/white"
                android:gravity="center|center_vertical"
                android:progressDrawable="@drawable/progress_drawable"
 />

progress_drawable.xml

put this xml in Drawable folder

<?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>
            <gradient 
                    android:startColor="#00000000"
                    android:centerColor="#00000000"
                    android:centerX="1"
                    android:endColor="#00000000"
                    android:angle="0"
            />
        </shape>
    </item>
    <item android:id="@android:id/secondaryProgress" >
        <clip android:clipOrientation="horizontal" android:gravity="left" >
            <shape>
                <gradient
                        android:startColor="@color/blue"
                        android:centerColor="@color/blue"
                        android:centerX="0.75"
                        android:endColor="@color/blue"
                        android:angle="0"
                />
            </shape>
        </clip>
    </item>

    <item android:id="@android:id/progress" >
        <clip android:clipOrientation="horizontal" android:gravity="left" >
            <shape>
                <gradient
                        android:startColor="@color/blue"
                        android:centerColor="@color/blue"
                        android:centerX="0.75"
                        android:endColor="@color/blue"
                        android:angle="0"
                />
            </shape>
        </clip>
    </item>

</layer-list>
Biraj Zalavadia
  • 28,348
  • 10
  • 61
  • 77
1

In your xml put this

<SeekBar  
        .....               
        android:background="@null"
        android:splitTrack="false"
        android:progressDrawable="@drawable/progress_drawable"
 />

and in your seek_bar_progress drawable leave blank the background part but put your gradient part with clip tag.

<item android:id="@android:id/secondaryProgress" >
    <clip android:clipOrientation="horizontal" android:gravity="left" >
        <shape>
            <gradient
                    android:startColor="@color/blue"
                    android:centerColor="@color/blue"
                    android:centerX="0.75"
                    android:endColor="@color/blue"
                    android:angle="0"
            />
        </shape>
    </clip>
</item>
Bajrang Hudda
  • 3,028
  • 1
  • 36
  • 63