androidxmlkotlinmaterial-components-androidandroid-slider

How to disable Material Slider Widget


I'm using Slider Widget from google Material library and I need to prevent user from slide the widget for a while. Is there any way to do that? (I prefer to not using onPositionChanged() method)


<com.google.android.material.slider.Slider
        android:id="@+id/speakerVolumeBottomSheetSeekbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/SliderMaterialTheme"
        app:labelBehavior="gone"
        android:value="0.5"
        app:thumbColor="@color/colorAccent"
        app:trackColorActive="@color/colorAccent"
        app:trackColorInactive="@color/white_22_opacity" />


Solution

  • Use:

       <com.google.android.material.slider.Slider
            android:enabled="false"/>
    

    or programmatically:

    slider.isEnabled = false