An extension of the Preference support library that originally fixed various bugs found in early versions (now all resolved). Currently includes a customisable NumberPickerPreference and TimePickerPreference.
Minimum SDK is 11 to align with NumberPicker.
Contributions are welcome, please submit a pull request.
Add the following to your build.gradle
:
compile 'me.philio:preferencecompatextended:1.2.2'
The latest v7 and v14 preference libraries are included and are not required
Create a fragment that extends the included PreferenceFragmentCompat
Replace imported android.support.v7.preference.PreferenceFragmentCompat
with me.philio.preferencecompatextended.PreferenceFragmentCompat
Note: Full package name is not required as the preferences are in the same package as the preference support library, Android Studio produces a warning but your project will build and run without issue.
<NumberPickerPreference
android:defaultValue="1"
android:key="number_picker"
android:title="A numeric preference"
app:maxValue="100"
app:minValue="1"
app:valueAsSummary="true" />
minValue
- The minimum value of the number pickermaxValue
- The maximum value of the number pickervalueAsSummary
- Whentrue
, sets the current value as the summary text, optionally formatted usingsummaryFormat
if setsummaryFormat
- String format to use as the summary textdescendantFocusable
- Set the descendantFocusability of the number pickerwrapSelectorWheel
- Sets whether the selector wheel should wrap around the minimum and maximum valuessubtitleText
- Set the subtitle text, shown to the right of the number picker in the dialog
<TimePickerPreference
android:key="time_picker"
android:title="A time picker preference"
app:defaultHours="10"
app:defaultMins="0"
app:timeAsSummary="true" />
timeAsSummary
- Whentrue
, sets the currently selected time as the summary text (default)timeFormat
- Time formatting method, eitherinherit
to use system setting orhours12
/hours24
for 12 and 24 hour settings, automatically set tocustom
whentimeFormatString
is settimeFormatString
- Format string to be passed toSimpleDateFormat
, overridestimeFormat
if setdefaultHours
- Set the default value in hours, requiresdefaultMins
defaultMins
- Set the default value in minutes, requiresdefaultHours
dialogTimeFormat
- Set the dialog 24 hour setting, eitherinherit
to use system setting orhours12
/hours24
for 12 and 24 hour settings
In your theme just set the preferenceTheme
to the provided PreferenceTheme
:
<item name="preferenceTheme">@style/PreferenceTheme</item>
For SDK 11+ devices this inherits from PreferenceThemeOverlay
.
For SDK 14+ devices this inherits from PreferenceThemeOverlay.v14.Material
.
To ensure correct styling of the TimePicker
on all L+ devices you may need to add a timePickerDialogTheme
to your app theme:
<item name="android:timePickerDialogTheme">@style/MyTimePickerDialogTheme</item>
Copyright 2015-2017 Phil Bayfield
Copyright (C) 2015 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.