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?

Nikola Despotoski
  • 49,966
  • 15
  • 119
  • 148
Mark Smith
  • 880
  • 1
  • 8
  • 25
  • *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. – user Aug 25 '15 at 07:04
  • Thanks! Absolutely correct. Doh! – Mark Smith Aug 26 '15 at 08:43
  • 1
    @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? – snapfractalpop May 11 '17 at 01:44
  • 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. – user May 11 '17 at 04:18

1 Answers1

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
Carlos Anyona
  • 641
  • 1
  • 7
  • 17