13

I am working with a SeekBar that works perfectly fine. But I want to increase the height of the Progress bar, as the native height is not as high.

So how can I change the height of the progress bar, either dynamically or through XML?

amira
  • 416
  • 1
  • 7
  • 24
Usman Kurd
  • 7,212
  • 7
  • 57
  • 86

3 Answers3

3

To create custom seekbar, add in your xml file below code:

  <androidx.appcompat.widget.AppCompatSeekBar
                android:id="@+id/seek_homelayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="@dimen/_10sdp"
                android:maxHeight="8dip"
                android:minHeight="8dip"
                android:progressBackgroundTint="@color/thumb"
                android:progressDrawable="@drawable/sb_progress_drawable"
                android:progressTint="@color/black"
                android:secondaryProgressTint="@color/colorPrimary"
                android:thumb="@drawable/sb_thumb"
                android:thumbTint="@color/colorPrimary" />

Create sb_progress_drawable.xml file in drawable:

<?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">
            <solid android:color="#26FFFFFF"/>
        </shape>
    </item>

    <item android:id="@android:id/secondaryProgress">
        <scale
            android:scaleWidth="100%" >
            <shape android:shape="rectangle">
                <solid android:color="#26FFFFFF"/>
            </shape>
        </scale>
    </item>

    <item android:id="@android:id/progress">
        <scale
            android:scaleWidth="100%" >
            <shape android:shape="rectangle">
                <solid android:color="#FFFFFF"/>
            </shape>
        </scale>
    </item>

</layer-list>

If you want to use thumb on to seekbar then add sb_thumb.xml file in your drawable:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">
    <size android:width="12dp"
        android:height="12dp" />
    <solid android:color="@color/colorPrimary" />
</shape>
Anshul1507
  • 529
  • 6
  • 14
MEGHA DOBARIYA
  • 1,622
  • 9
  • 7
2

You have maxHeigh and minHeight attributes. This attributes will determinate the height of your seekbar.

android:maxHeight="3dp" 
android:minHeight="3dp"

https://www.lvguowei.me/post/customize-android-seekbar-color/

Cheers.

Ricard
  • 1,223
  • 1
  • 13
  • 17
0

None of the above works, simply set android:layout_height="10dp" to whatever value you want!

<SeekBar
    android:id="@+id/seekBar"
    style="?android:attr/progressBarStyleHorizontal"
    android:layout_width="0dp"
    android:layout_height="10dp"

    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent" />
Osama Remlawi
  • 2,356
  • 20
  • 21