Info @ meCoffee 4891bf4909 First commit | %!s(int64=6) %!d(string=hai) anos | |
---|---|---|
.. | ||
example | %!s(int64=6) %!d(string=hai) anos | |
res | %!s(int64=6) %!d(string=hai) anos | |
src | %!s(int64=6) %!d(string=hai) anos | |
.gitattributes | %!s(int64=6) %!d(string=hai) anos | |
.gitignore | %!s(int64=6) %!d(string=hai) anos | |
AndroidManifest.xml | %!s(int64=6) %!d(string=hai) anos | |
LICENSE.txt | %!s(int64=6) %!d(string=hai) anos | |
README.md | %!s(int64=6) %!d(string=hai) anos | |
build.gradle | %!s(int64=6) %!d(string=hai) anos | |
screenshot.png | %!s(int64=6) %!d(string=hai) anos |
float
between 0.0
and 1.0
SliderPreference.getValue()
or SharedPreferences.getFloat()
SliderPreference.setSummary(CharSequence[] summaries)
android:summary="@array/string_array_of_summaries"
String
still works tooDialogPreference
android:dialogMessage
Paste or clone this library into the /libs
folder, in the root directory of your project. Create a new folder: /libs
if not already present. (This step is not required - only for keeping cleaner project structure)
Edit settings.gradle
by adding the library. You have also define a project directory for the library. Your settings.gradle
should look like below:
include ':app', ':SliderPreference'
project(':SliderPreference').projectDir = new File('libs/SliderPreference')
In app/build.gradle
add the SliderPreference library as a dependency:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile project(":SliderPreference")
}
Sync project, clean and build. You can use the SliderPreference as part of your project now.
Before you can add a SliderPreference
to your application, you must first add a library reference:
<!-- preferences.xml -->
<net.jayschwa.android.preference.SliderPreference
android:key="my_slider"
android:title="@string/slider_title"
android:summary="@array/slider_summaries"
android:defaultValue="@string/slider_default"
android:dialogMessage="@string/slider_message" />
<!-- strings.xml -->
<string name="slider_title">Temperature</string>
<string-array name="slider_summaries">
<!-- You can define as many summaries as you'd like -->
<!-- The active summary will reflect the preference's current value -->
<item>Freezing</item> <!-- 0.00 to 0.25 -->
<item>Chilly</item> <!-- 0.25 to 0.50 -->
<item>Warm</item> <!-- 0.50 to 0.75 -->
<item>Boiling</item> <!-- 0.75 to 1.00 -->
</string-array>
<item name="slider_default" format="float" type="string">0.5</item>
<string name="slider_message">Optional message displayed in the dialog above the slider</string>
It is possible to define the default value directly in the attribute. The summary can also be a regular string, instead of a string array:
<net.jayschwa.android.preference.SliderPreference
android:summary="This summary is static and boring"
android:defaultValue="0.5" />
Sliders are recommended by Android's official design documentation for specific types of settings:
Use this pattern for a setting where the range of values are not discrete and fall along a continuum.
Despite this recommendation, the Android SDK does not actually provide a Preference
with slider functionality. Various custom implementations can be found around the web, but many have issues such as:
This library aims to be as consistent as possible with the design pattern and Android's built-in Preference
implementations.
This library is licensed under the MIT License. A copy of the license is provided in LICENSE.txt:
Copyright 2012 Jay Weisskopf
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.