Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Seekbar in setting?

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>
like image 787
nanda Avatar asked Jan 04 '16 08:01

nanda


People also ask

How do you implement SeekBar?

Step1: Create a new project. After that, you will have java and XML file. Step2: Open your xml file and add a SeekBar and TextView for message as shown below, max attribute in SeekBar define the maximum it can take. Assign ID to SeekBar And TextView.

What is the use of SeekBar in Android?

A SeekBar is an extension of ProgressBar that adds a draggable thumb. The user can touch the thumb and drag left or right to set the current progress level or use the arrow keys. Placing focusable widgets to the left or right of a SeekBar is discouraged.

How do I set SeekBar value in Kotlin?

You need to call setOnSeekbarChangeListener() on your seekbar object and let for example your activity implement OnSeekbarChangeListener() and in that function you can do whatever you want.

What does a SeekBar do?

In Android, SeekBar is an extension of ProgressBar that adds a draggable thumb, a user can touch the thumb and drag left or right to set the value for current progress. SeekBar is one of the very useful user interface element in Android that allows the selection of integer values using a natural user interface.


2 Answers

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" />
like image 66
Scorpius Avatar answered Sep 30 '22 19:09

Scorpius


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

like image 26
rubengees Avatar answered Sep 30 '22 19:09

rubengees