4

I'm trying to implement SeekBarPreference into my preference XML. I have attempted to use MrBIMC seekbar (https://github.com/MrBIMC/MaterialSeekBarPreference) which mostly worked but due to it being old, there were some issues I had to come up with ugly solutions for.

<SeekBarPreference
        android:defaultValue="5"
        android:dependency="a_different_preference"
        android:key="seekbar_key"
        android:max="40"
        android:summary="Select your value"
        android:title="Seekbar value"
        app:iconSpaceReserved="false"
        asp:min="1" />

The above code does mostly what I want, except I can't figure out how to add a measurement value.

sample:msbp_measurementUnit="km"

The above is what is used in the MrBIMC library to set a unit after the value, but can't achieve anything similar natively.

Lastly, in my preferences.xml, I get the error "Element SeekBarPreference is not allowed here" which is preventing the IDE from showing me any suggestions to get what I am after.

Edit: Since asking this, I have learnt that the native seekbarpreference does not seem to have the ability to add a measurement unit after its value... So, how exactly can I create a custom view, that looks and behaves the same, but has the ability to input a measurement unit?

NicCoe
  • 409
  • 4
  • 17

1 Answers1

0

This Stack Overflow question I had found has used a SeekBarPreference as an example of how to make a custom Preference: Creating Custom Preference

In addition to this, in the XML file, you can just add a spinner to seekbar_preference.xml.

Or, an even easier solution (but not really what you want) is to add a separate ListPreference to your preferences.xml file and input the preferred unit of measurement from there.

Harsh Modani
  • 205
  • 1
  • 11