Friday, 7 June 2019

How can I add a RangeBar to my preferences.xml?

I'm using the androidx Preferences library to implement my settings.

However unfortunately Android does not have a RangeBar with 2 thumbs, only a SeekBarPreference with 1 thumb.

What is the best simple way to go about creating my own RangeBar? I've tried multiple libraries such as: https://github.com/nickwinder/range-bar-preference and https://android-arsenal.com/details/1/1756 and they simply don't compile.

For context, I'm trying to create a RangeBar between 1 and 99 which includes a min value and max value.

<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <Preference
       android:title="Settings"
       android:key="settings_category"
       android:layout="@layout/preference_title"/>
    <SeekBarPreference
        android:layout="@layout/preference_widget_seekbar_override"
        app:showSeekBarValue="false"
        android:max="30"
        android:defaultValue="10"
        android:key="distance"
        android:title="Max distance (km)"/>

    <RangeBarPreference
        .../>



from How can I add a RangeBar to my preferences.xml?

No comments:

Post a Comment