Reputation: 5745
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.
Upvotes: 18
Views: 28015
Reputation: 1
just add this two line of code into your seekbar xml
android:thumbTint="#00D1CEB0"
android:splitTrack="false"
Upvotes: 0
Reputation: 1579
The easiest & simplest way to do it is just add this line in your Seekbar view in its xml
android:thumb="@android:color/transparent"
Upvotes: 5
Reputation: 5745
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"
/>
Upvotes: 29
Reputation: 192
You can hide the seekbar thumb by setting arbitrarily large thumb offset value, which will move the thumb out of view. For example,
mySeekBar.setThumbOffset(10000); // moves the thumb out of view (to left)
To show the thumb again, set the offset to zero or other conventional value:
mySeekBar.setThumbOffset(0); // moves the thumb back to view
This approach works in all API levels.
Upvotes: 2
Reputation: 2741
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" />
Upvotes: 10