Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using SeekBarPreference

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?

like image 504
Mark Smith Avatar asked Aug 23 '15 17:08

Mark Smith


1 Answers

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
like image 73
Carlos Anyona Avatar answered Oct 08 '22 06:10

Carlos Anyona