MultiSlider icon indicating copy to clipboard operation
MultiSlider copied to clipboard

How to set custom drawable for thumb?

Open drunkendaddy opened this issue 7 years ago • 3 comments

I tried:

slider.getThumb(0).setThumb(ContextCompat.getDrawable(getContext(),
                R.drawable.slider_thumb_bg));
slider.getThumb(1).setThumb(ContextCompat.getDrawable(getContext(),
                R.drawable.slider_thumb_bg));

but not working. thumb is not showing.

drunkendaddy avatar Mar 12 '18 14:03 drunkendaddy

Hi @drunkendaddy, drawable for thumbs is more complicated than a just image

See here for API19 and lower: https://github.com/apptik/MultiSlider/blob/master/lib/src/main/res/drawable/multislider_thumb_material.xml See here for API21 and higher: https://github.com/apptik/MultiSlider/blob/master/lib/src/main/res/drawable-v21/multislider_thumb_material_anim.xml

And docs from Android guide: https://developer.android.com/guide/topics/resources/drawable-resource.html#StateList

bmx666 avatar Mar 14 '18 09:03 bmx666

just use android:thumb="@drawable/your_drawable" in xml

Kelvao avatar Nov 29 '18 17:11 Kelvao

Is it possible to use, for example, gradient image as a source for thumb? I was trying to set <?xml version="1.0" encoding="utf-8"?> <shape android:shape="oval" xmlns:android="http://schemas.android.com/apk/res/android"> <gradient android:startColor="@color/age_select_start" android:centerColor="@color/age_select_middle" android:endColor="@color/age_select_end"/> </shape> But, when I tried to set for v21 as follows: `

<item
    android:id="@+id/pressed"
    android:drawable="@drawable/thumb_age_internal_drawable"
    android:state_pressed="true"/>
<item
    android:id="@+id/unpressed"
    android:drawable="@drawable/thumb_age_internal_drawable"/>
<!--<transition
    android:drawable="@drawable/multislider_thumb_unpressed_to_pressed_animation"
    android:fromId="@+id/unpressed"
    android:toId="@+id/pressed"/>
<transition
    android:drawable="@drawable/multislider_thumb_pressed_to_unpressed_animation"
    android:fromId="@+id/pressed"
    android:toId="@+id/unpressed"/>-->

` any images just disappeared. Can you provide example how to use custom drawable?

Syjgin avatar Mar 25 '19 05:03 Syjgin