40

I have this SeekBar:

        <SeekBar
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="26dp"
        android:id="@+id/seekbar"
        android:visibility="gone"
        android:maxHeight="3dp"/>

I have tried to change this SeekBar thickness using maxHeight. But nothing changed. It looks like this:

enter image description here

I want to change this SeekBar's thickness to 3dp and make look like this: enter image description here

So my question is it possible to change SeekBar thickness somehow? If yes, how?

Joe Rakhimov
  • 3,734
  • 7
  • 36
  • 91

6 Answers6

61

You have to change progressDrawable and thumb of SeekBar to adjust it's thickness :

<SeekBar
    android:id="@+id/seekBar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/indSeekBar"
    android:layout_marginTop="48dp"
    android:progressDrawable="@drawable/seek_bar"
    android:thumb="@drawable/seek_thumb"
    />

Add in drawable folder seek_bar.xml :

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@android:id/background">
        <shape
            android:shape="line">
            <stroke
                android:color="@color/seek_bar_background"
                android:width="@dimen/seek_bar_thickness"/>
        </shape>
    </item>
    <item android:id="@android:id/secondaryProgress">
        <clip>
            <shape
                android:shape="line">
                <stroke
                    android:color="@color/seek_bar_secondary_progress"
                    android:width="@dimen/seek_bar_thickness"/>
            </shape>
        </clip>
    </item>

    <item android:id="@android:id/progress">
        <clip>
            <shape
                android:shape="line">
                <stroke
                    android:color="@color/seek_bar_progress"
                    android:width="@dimen/seek_bar_thickness"/>
            </shape>
        </clip>
    </item>

</layer-list>

seek_thumb.xml :

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">
    <size
        android:height="@dimen/seek_bar_thumb_size"
        android:width="@dimen/seek_bar_thumb_size"
        />
    <solid android:color="@color/seek_bar_progress"/>
</shape>

Add to dimension resources (change this to adjust thickness) :

<dimen name="seek_bar_thickness">4dp</dimen>
<dimen name="seek_bar_thumb_size">20dp</dimen>

Add color resources :

<color name="seek_bar_background">#ababab</color>
<color name="seek_bar_progress">#ffb600</color>
<color name="seek_bar_secondary_progress">#3399CC</color>

enter image description here

ahsanali274
  • 381
  • 1
  • 13
Vaibhav Jani
  • 12,018
  • 10
  • 60
  • 71
  • Could you explain how to "add to dimension resources"? I see "drawable", "layout", and "values" in my `res` folder in Android Studio, but no "dimension" – stevendesu Oct 16 '19 at 17:56
  • 2
    @stevendesu create file dimens.xml in values resource folder, technically you can declare any string, color, dimension resources in any XML file in values folder enclosed in tag – Vaibhav Jani Oct 17 '19 at 09:28
14

You should do like this:

<SeekBar
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="20dp"
    android:thumb="@drawable/seek"
    android:progressDrawable="@drawable/seek_style"
    />

The thumb is the circle which can be dragged, and the progressDrasable is the style of progress.

seek_style.xml:

<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/secondaryProgress">
        <clip>
            <shape>
                <corners android:radius="5dip" />
                <gradient
                    android:startColor="#80ffd300"
                    android:centerColor="#80ffb600"
                    android:centerY="0.75"
                    android:endColor="#a0ffcb00"
                    android:angle="270"
                    />
            </shape>
        </clip>
    </item>

    <item android:id="@android:id/progress">
        <clip>
            <shape>
                <corners android:radius="5dip" />
                <gradient
                    android:startColor="#ff0099CC"
                    android:centerColor="#ff3399CC"
                    android:centerY="0.75"
                    android:endColor="#ff6699CC"
                    android:angle="270"
                    />
            </shape>
        </clip>
    </item>
</layer-list>

seek.xml:

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">
    <size
        android:width="20dp"
        android:height="20dp"
        />
    <solid android:color="#60f0"/>
</shape>
Fruit
  • 6,309
  • 3
  • 42
  • 57
zhangxiaoping
  • 230
  • 2
  • 6
3

You can use the Slider provided by the Material Components Library.

Use the app:trackHeight="xxdp" (the default value is 4dp) to change the height of the track bar.

    <com.google.android.material.slider.Slider
        app:trackHeight="12dp"
        .../>

enter image description here

If you want to change also the thumb radius you can use the app:thumbRadius attribute:

        <com.google.android.material.slider.Slider
            app:trackHeight="12dp"
            app:thumbRadius="16dp"
            ../>
           

enter image description here

It requires the version 1.2.0 of the library.

Gabriele Mariotti
  • 192,671
  • 57
  • 469
  • 489
1

I solved the problem with: android:scaleX="2"

Master
  • 606
  • 6
  • 18
0

Just set scaleY for seekbar height, and padding to remove outside padding.

 <androidx.appcompat.widget.AppCompatSeekBar
        android:id="@+id/seekbar"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:paddingStart="0sp"
        android:paddingTop="0sp"
        android:scaleY="3" />
Gundu Bandgar
  • 2,383
  • 1
  • 15
  • 20
-5

You can change the thickness of your seekbar using the attributes minHeight and maxHeight

android:minHeight="5dp"

android:maxHeight="5dp"

Here's how I'd do it in your xml:

<SeekBar
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="26dp"
    android:id="@+id/seekbar"
    android:visibility="gone"
    android:minHeight="5dp"
    android:maxHeight="5dp"/>
Prad
  • 495
  • 7
  • 15