Android draw custom thumb in XML

Please help define your own XML resource for SeekBar Thumb. In this XML drawing, I would like to define custom shapes for state_selectedand state_pressed.

As I understand it, in the SeekBar definition in XML, we must put android:thumb="@drawable/listview_bg_selector"where listview_bg_selectorit looks like this:

<?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 tried code from drawables with shapes here, but nothing worked as expected, I just saw the default SeekBar. Are there any examples for this problem?

+5
source share
3 answers

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

, Spinner, Switch ..

+3

, , -, ,

+4

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 can set code boundaries, but I'm not sure about that.

+3
source

All Articles