Sergii
Sergii

Reputation: 1551

Android draw own seekbar thumb in XML

Please help to define own XML drawable for SeekBar Thumb. In this XML drawable I would like to define custom shapes for state_selected and state_pressed.

As I understand, in the SeekBar definition in XML we have to put android:thumb="@drawable/listview_bg_selector" where listview_bg_selector looks like:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_selected="false"
        android:state_pressed="false"
        android:drawable="@drawable/seekbar_thumb_default" /> 
    <item android:state_pressed="true"
        android:drawable="@drawable/seekbar_thumb_clicked"
        />
    <item android:state_selected="true"
        android:state_pressed="false"
        android:drawable="@drawable/seekbar_thumb_selected" 
         />
</selector>

But what to do next, I've tried here code from drawables with shapes, but nothing worked properly, I just saw default SeekBar. Are there any examples for this issue?

Upvotes: 6

Views: 11820

Answers (2)

Marcus
Marcus

Reputation: 6717

For future answer-seekers, I used holo-colors.com to create my own custom SeekBar, which I am perfectly satisfied with.

They also provide functions to create other android elements such as Spinner, Switch, etc.

Upvotes: 3

ornay odder
ornay odder

Reputation: 135

something like this solved the problem for me.

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@drawable/seek_thumb_pic">
        <shape android:shape="rectangle" />
    </item>

</selector>

another way might be setting bounds in code but I`m not sure about this.

Upvotes: 3

Related Questions