Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide/show thumb drawable in a SeekBar

I have a SeekBar with a custom drawable for the Thumb, and I would like to be able to show/hide it based on another control I have.

I have tried loading the drawable from resources, and then using SeekBar.setThumb() with the drawable, or null.

That hides it (the set to null), but I can never get it back.

like image 200
Andrew Mackenzie Avatar asked Dec 31 '13 10:12

Andrew Mackenzie


People also ask

How do I change my thumb SeekBar?

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

How do I change the SeekBar thumb size on android?

Show activity on this post. Then I used vector code in . 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.

How can I make my own 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.

What is discrete SeekBar?

In Android Discrete SeekBar is just an advancement of progressBar just like the SeekBar, the only difference in SeekBar and discrete SeekBar being that in discrete SeekBar, we can only set the value only to discrete values like 1, 2, 3, and so on.


3 Answers

The best way to do this is to set the drawable for the thumb from XML (as I was doing all along) and then when you want to hide/show the Thumb drawable, just manipulate it's alpha value:

// Hide the thumb drawable if the SeekBar is disabled
if (enabled) {
    seekBar.getThumb().mutate().setAlpha(255);
} else {
    seekBar.getThumb().mutate().setAlpha(0);
}

Edit:

If thumb appearing white after setting alpha to zero, try adding

<SeekBar
    ....
    android:splitTrack="false" 
/>
like image 108
Andrew Mackenzie Avatar answered Oct 22 '22 13:10

Andrew Mackenzie


Hide your thumb in a SeekBar via xml

 android:thumbTint="@color/transparent"

for Example

<SeekBar
android:id="@+id/seekBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="false"
android:thumb="@color/gray"
android:thumbTint="@android:color/transparent" />
like image 10
krishnan Avatar answered Oct 22 '22 13:10

krishnan


The easiest & simplest way to do it is just add this line in your Seekbar view in its xml

android:thumb="@android:color/transparent"
like image 5
Nasib Avatar answered Oct 22 '22 13:10

Nasib