Search code examples
androidxmlkotlinandroid-preferences

Androidx SeekBarPreference xml attribute setMax not found


I'm trying to implement androidx SeekBarPreference, according to the docs I might be able to use setMax attribute in my xml, yet I get the following error when doing so:

in xml:

<SeekBarPreference
    app:key="preference_key"
    app:title="@string/preference"
    app:showSeekBarValue="true"
    app:setMax="10"/>

the error:

root_preferences.xml:53: AAPT: error: attribute setMax (aka 
gls.dev.MyApplication:setMax) not found.

However, when setting the properties in code it works like a charm:

findPreference<SeekBarPreference>("preference_key")?.apply {
    max = 10
    min = 1
    seekBarIncrement = 1
    isAdjustable = true
}

Solution

  • The max attribute currently only exists in the android: namespace, so you will need to use:

    <SeekBarPreference
        app:key="preference_key"
        app:title="@string/preference"
        app:showSeekBarValue="true"
        android:max="10"/>