kamaal4
kamaal4

Reputation: 53

How to show slider value above the slider also when we are not sliding using material.slider in Android?

This is how I want to show the value of the slider. Please find the picture

Sample slider image

Upvotes: 3

Views: 3303

Answers (2)

Aatman Vaidya
Aatman Vaidya

Reputation: 51

You can set the label behaviour "visible" in the XML file. So in the slider XML code, you just need to add

app:labelBehavior="visible"

Below I am attaching a sample XML code for the same.

    <com.google.android.material.slider.Slider
        android:id="@+id/seek_bar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:valueFrom="1"
        android:valueTo="100"
        android:layout_gravity="center"
        android:layout_margin="15dp"
        app:tickColor="#0000FF"
        app:labelStyle="@style/Tooltip"
        app:labelBehavior="visible"
        />

Upvotes: 3

MatPag
MatPag

Reputation: 44861

This is currently not supported, the available options in LabelFormatter (which can be applied to sliders with slider.setLabelFormatter(...) are:

  • LabelFormatter.LABEL_FLOATING: Label visible during interaction only
  • LabelFormatter.LABEL_WITHIN_BOUNDS: Label visible during interaction only
  • LabelFormatter.LABEL_GONE: Label never visible

You can find the code here with the extensive javadoc explanation.

You could open a feature request for this on the Material GitHub issues page

Upvotes: 2

Related Questions