Using SeekBarPreference
Asked Answered
S

1

8

What's the deal with SeekBarPreference? Let me expand...

If I put a SeekBarPreference in my PreferenceScreen xml, it works fine (I can run it on phone and emulator), but Android Studio reports `Element SeekBarPreference is not allowed here. Simple XML which shows this:

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >

<SeekBarPreference
    android:key="fontSize"
    android:title="@string/fontSize_title"
    android:summary="@string/fontSize_summary"
    android:max="12"
    android:defaultValue="4" />

</PreferenceScreen>

If I try to extend SeekBarPreference (which is what I really want to do), Android Studio Cannot resolve symbol SeekBarPreference both at the import and at the extends. Simple Java file to show this:

import android.preference.SeekBarPreference;

public class FontSizePreference extends SeekBarPreference {}

(Also happens if I just use SeekBarPreference sbp; in code.)

The source code for SeekBarPreference is in /Sdk/sources/android-22/android/preference, just like EditTextPreference. I don't see anything special about it.

I can't find any documentation at developer.android.com about it, though.

What nugget of information am I missing? What's special about this compared with, say, EditTextPreference, which I can include in XMLs and extend and use in code without problems?

Solubility answered 23/8, 2015 at 17:20 Comment(4)
I don't see anything special about it. - You've missed the @hide annotation which will remove it from the javadocs. That class is not part/intended for public use, so although is there you shouldn't be using it.Shiny
Thanks! Absolutely correct. Doh!Solubility
@Luksprog why shuoldn't we use it if it's there? Is this something where the implementation details may not be "stable" and later changes could break compatibility?Granvillegranvillebarker
The question is a bit old and the SeekBarPreference is now available both in the sdk and the preference compatibility library, so you can use it. As that class had the @hide annotations it meant it shouldn't had been considered as public API at that point. Accessing private APIs isn't recommended because you'll have a fragile implementation subjected to break very easily whenever the developers of the SDK modify the class or remove it altogether.Shiny
T
1

I had similar problem and this worked for me:

instead of using:

<PreferenceScreen/>

Try using:

<android.support.v7.preference.PreferenceScreen/>

It worked like a charm. It simply implies that all this works best when using support libraries. So, in your Custom seekbar you may need to import:

android.support.v7.preference.SeekBarPreference
Tyrannicide answered 22/1, 2019 at 9:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.