Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set the background of SeekBar

I want to set the SeekBar like this:

enter image description here

But my SeekBar is looking like this:

enter image description here

That's mean it over the two small "sun"

Here is my code:

<SeekBar
        android:id="@+id/seekBar"
        android:layout_span="2"
        android:layout_width="fill_parent"
        android:progressDrawable="@drawable/background_custom"
        android:paddingTop="1dp"
        android:paddingBottom="1dp"
        android:thumb="@drawable/thumb_custom"
        android:minHeight="20dp"
        android:maxHeight="40dp"
        android:layout_height="45dp"
        android:layout_centerVertical="true"
        android:max="100"
        android:progress="100"
        android:paddingLeft="1dp"
        android:paddingRight="1dp"
            android:background="@drawable/my_back_ground"
        />

Xml of background_custom:

<?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>

            <size
                android:height="50dp"
                android:width="50dp" />
            <corners android:radius="50dp" />
        </shape>

    </item>

    <item android:id="@android:id/progress">
        <clip>
            <shape>

                <solid android:color="#11ff00" />
                <corners android:radius="30dp" />
            </shape>
        </clip>

    </item>

</layer-list>

Xml of thumb_custom:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="#ffe38c" />
    <size
        android:width="35dp"
        android:height="35dp" />
    <corners android:radius="35dp" />
    <item android:id="@android:id/background"
        android:drawable="@drawable/led_sang"/>
</shape>
like image 917
Khuong Avatar asked Sep 25 '15 03:09

Khuong


People also ask

How do I customize SeekBar?

Now go to the activity_main. xml create a layout and inside the layout add a SeekBar. Specify the height width of SeekBar and the max progress that you want to use set progress to 0. This will create a customized Seekbar inside activity_main.

How do I change the color of my SeekBar track?

If you are using default SeekBar provided by android Sdk then their is a simple way to change the color of that . just go to color. xml inside /res/values/colors. xml and change the colorAccent.

How do I set the value of SeekBar?

One possible solution would be to set seekBar. setMax(20) (or android:max="20" in XML), and whenever you use or display the value, multiply it by 10. The SeekBar would then appear to move at least 20 at a time.

How do I change my thumb SeekBar?

Just add android:thumbTint="@color/yourColor" in your seekbar.


1 Answers

I already solve this problem by replace this line android:progressDrawable="@drawable/background_custom" to android:progressDrawable="#80FFFF00". This will make the 50% transparent of the yellow color.

like image 136
Khuong Avatar answered Sep 30 '22 22:09

Khuong