Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android draw own seekbar thumb in XML

Tags:

android

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?

like image 845
Sergii Avatar asked Jul 09 '12 14:07

Sergii


People also ask

How can I make my own SeekBar?

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 thumb size on my Android?

xml file, which has attrs android:width="28dp" and android:height="28dp" in the vector tag. Here we can change the size of the thumb. Save this answer.

What is SeekBar thumb?

android.widget.SeekBar. A SeekBar is an extension of ProgressBar that adds a draggable thumb. The user can touch the thumb and drag left or right to set the current progress level or use the arrow keys. Placing focusable widgets to the left or right of a SeekBar is discouraged.


2 Answers

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.

like image 96
Marcus Avatar answered Oct 18 '22 23:10

Marcus


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.

like image 21
ornay odder Avatar answered Oct 18 '22 23:10

ornay odder