How to use Seekbar in setting?
Asked Answered
C

2

8

I want to use Seekbar in setting to choose number 1 to 10. Is there any way to do this? I extend PreferenceActivity for my setting activity.

As I found from here, but I don't know how to create Seekbar inside of the PreferenceScreen. Thank in advance. Here is activity

 public class UserSettingActivity extends PreferenceActivity {
    @Override

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);        

         addPreferencesFromResource(R.xml.settings);    }
}

And setting.xml

 <?xml version="1.0" encoding="utf-8"?>

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >

 

    <PreferenceCategory android:title="@string/pref_user_profile" >

        <EditTextPreference

                android:title="@string/pref_user_name"

                android:summary="@string/pref_user_name_summary"

                android:key="prefUsername"/>

    </PreferenceCategory>

     

    <PreferenceCategory android:title="@string/pref_update_setting" >

        <CheckBoxPreference

            android:defaultValue="false"

            android:key="prefSendReport"

            android:summary="@string/pref_send_report_summary"

            android:title="@string/pref_send_report" >

        </CheckBoxPreference>

 

        <ListPreference

            android:key="prefSyncFrequency"

            android:entries="@array/syncFrequency"

            android:summary="@string/pref_sync_frequency_summary"

            android:entryValues="@array/syncFrequencyValues"

            android:title="@string/pref_sync_frequency" />

    </PreferenceCategory>

 

</PreferenceScreen>
Clance answered 4/1, 2016 at 8:40 Comment(2)
Where is your code? Please edit your question to add codes.Arrington
I am not used to use tool.Some code are not appear in question.All I write is downloaded from above link.So,you can check it in the link.Sorry about that.Clance
C
17

If you don't mind using the Android.Support.v7.Preference Library, then you can use SeekBarPreference.

You could then use in XML:

<SeekBarPreference
            android:key="keyName"
            android:title="Property Label"
            android:summary="Summary."
            android:max="5"
            android:defaultValue="0" />
Cardsharp answered 17/1, 2017 at 0:15 Comment(1)
This is not a DialogPreference variant, means it will show the seek bar where the <SeekBarPreference/> tag located at the view hierarchy rather than inside a DialogPreference.Moquette
D
1

There is currently no SeekBarPreference out of the box, though I have seen some official source code.
Maybe you want to use this library: https://github.com/MrBIMC/MaterialSeekBarPreference

Doscher answered 4/1, 2016 at 9:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.