Material theme for preference widgets.
Backporting dat material look and functionality.
Available from API 7. Depends on appcompat-v7 and preference-v7 r23.1.1.
dependencies {
compile 'net.xpece.android:support-preference:0.5.3'
}Library version 0.5.1. Android version 4.4.
PreferenceCheckBoxPreferenceSwitchPreference- Using
SwitchCompatavailable from API 7
- Using
DialogPreference- Uses AppCompat Alert Dialog Material theme
EditTextPreferenceListPreferenceMultiSelectListPreference- Available since API 7
SeekBarDialogPreferenceextendsDialogPreference- Made public
SeekBarPreference- Made public
- According to http://www.google.com/design/spec/components/dialogs.html#dialogs-confirmation-dialogs
RingtonePreference- Coerced Ringtone Picker Activity from AOSP
XpPreferenceFragment- Handles proper Preference inflation and DialogPreference dialogs
SharedPreferencesCompatgetStringSetandputStringSetmethods allow persisting string sets even before API 11
- Material preference item layouts out of the box.
- Icon and dialog icon tinting and padding.
EditTextPreferenceunderstandsEditTextXML attributes.- Several preference widgets not publicly available in preference-v7 or SDK.
RingtonePreference,SeekBarPreference,SeekBarDialogPreference,MultiSelectListPreference
- Dividers.
- Subscreen navigation implementation.
Your preference fragment needs to extend XpPreferenceFragment.
Setup your preference items in the following method:
public void onCreatePreferences2(final Bundle savedInstanceState, final String rootKey) {
// ...
}Your settings activity theme needs to specify the following values:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Used to theme preference list and items. -->
<item name="preferenceTheme">@style/PreferenceThemeOverlay.Material</item>
<!-- Default preference icon tint color. -->
<item name="preferenceTint">@color/accent_state_list</item>
</style>Styling alertDialogTheme is recommended for a proper color theme. See the sample project.
If you want to use dividers, override onRecyclerViewCreated(RecyclerView) in your fragment:
@Override
public void onRecyclerViewCreated(RecyclerView list) {
list.addItemDecoration(new PreferenceDividerDecoration(getContext()).drawBottom(true));
}In appcompat-v7 r23.1.1 library there is a bug which prevents tinting of checkmarks in lists.
Call Fixes.updateLayoutInflaterFactory(getLayoutInflater()) right after
super.onCreate(savedInstanceState) in your Activity.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Fixes.updateLayoutInflaterFactory(getLayoutInflater());
setContentView(R.layout.activity_settings);
//...
}RingtonePicker will show only system ringtones/notification sounds by default.
If you want to include sounds from the external storage your app needs to request
the android.permission.READ_EXTERNAL_STORAGE permission in its manifest.
Don't forget to check this runtime permission before opening the picker on API 23.
As PreferenceScreen class is final and hardwired into preference system
I was unable to automate icon tinting and padding. However you are able to do this yourself:
Preference subs = findPreference("subs_screen");
PreferenceIconHelper subsHelper = new PreferenceIconHelper(subs);
subsHelper.setIconPaddingEnabled(true); // Call this BEFORE setIcon!
subsHelper.setIcon(R.drawable.some_icon);
subsHelper.setTintList(ContextCompat.getColorStateList(getPreferenceManager().getContext(), R.color.accent));
subsHelper.setIconTintEnabled(true);One solution is implemented in PreferenceScreenNavigationStrategy.ReplaceRoot class.
Please review the sample project for an example solution.
app:asp_tintapp:asp_tintModeapp:asp_tintEnabledapp:asp_iconPaddingEnabledapp:asp_dialogTintapp:asp_dialogTintModeapp:asp_dialogTintEnabledapp:asp_dialogIconPaddingEnabled
Application icons (48dp x 48dp) require no extra padding.
For smaller icons extra padding of 4dp on each side is needed.
Achieve this by using app:asp_iconPaddingEnabled
and app:asp_dialogIconPaddingEnabled attributes. Icon padding is enabled by default.
Since version 0.5.1 Proguard rules are bundled with the library.
0.5.3
- FIXED: Ringtone picker does not need
READ_EXTERNAL_STORAGEpermission even prior to Android 6.
0.5.2 Deprecated
- FIXED:
PreferenceScreenNavigationStrategy.ReplaceRootno longer crashes on screen rotation. - FIXED: Ringtone picker does not stop playback on screen rotation.
0.5.1 Deprecated
- NEW!
PreferenceScreenNavigationStrategyclass. - FIXED: Missing Proguard rules are now bundled with the library.
- FIXED: Incorrect icon size on Lollipop.
0.5.0 Deprecated
- Only supports appcompat-v7 with preference-v7 version 23.1.1 or newer!
- NEW! Based on preference-v7 instead of native preferences.
- Updated appcompat-v7 library to 23.1.1.
- Material SeekBar style across all platforms.
RingtonePreferenceis nowDialogFragmentbased.- Unmanaged preference icons (such as that of
PreferenceScreen) can be tinted viaPreferenceIconHelper. - Default preference icon tint specified by
preferenceTinttheme attribute. - Fixed divider color.
- Sample contains
PreferenceScreensubscreen handling.
0.4.3
- Last fully supported appcompat-v7 version is 23.0.1. After that ringtone picker crashes!
- No more
Resources.NotFoundExceptioninRingtonePickerActivity. Falls back to English. - Updated appcompat-v7 library to 22.2.1.
0.4.2 Deprecated
SeekBartinting can be turned off viaapp:asp_tintSeekBar="false"- Introduced missing
seekBarDialogPreferencestyle
0.4.1 Deprecated
- Ringtone picker strings are now taken dynamically from
androidandcom.android.providers.mediapackages, falls back to EnglishThese are accessible viaRingtonePickerActivity.get*String(Context)
0.4.0 Deprecated
- NEW! Implemented SeekBarPreference according to http://www.google.com/design/spec/components/dialogs.html#dialogs-confirmation-dialogs
- FIXED: tinting/padding in DialogPreference and SeekBarDialogPreference
AppCompatPreferenceActivity and PreferenceFragment now implement Factory- NEW! app:asp_dialogIconPaddingEnabled attribute
0.3.0 Deprecated
- Removed
MultiCheckPreferenceas it was only partially implemented andMultiSelectListPreferenceprovides the same function. MultiSelectListPreferenceis now available since API 7 (formerly API 11). UsesJSONArrayto persistSet<String>.- API for persisting and accessing string sets since API 7 is available via
SharedPreferencesCompat. Preferences now supportapp:asp_iconPaddingEnabledattribute which allows to better align non-launcher icons to 16dp keyline.Custom preferences are now recycled which fixed animation issues on Lollipop.- Custom preferences are now always inflated on all platforms if using
AppCompatPreferenceActivityand/or customPreferenceFragment. - Library no longer includes
android.permission.READ_EXTERNAL_STORAGEpermission (used to read ringtones). You have to do it yourself.- This is needed because the custom picker is part of the app and not provided by system.
You are of course free to useandroid.preference.RingtonePreferencewhen necessary.
0.2.2 Deprecated
- optional tinting
via.app:asp_tintIcon="true"andapp:asp_tintDialogIcon="true"andasp_tintandasp_tintMode
0.2.1 Deprecated
- No need for
net.xpece.android.support.preference.prefix in XML files defining preferences, framework will choose automatically:On Lollipop nativePreference,CheckBoxPreference,SwitchPreferencewill be used.Otherwise support version will be used.Force either version by using fully qualified class name.You need to useAppCompatPreferenceActivityor specialPreferenceFragmentboth of which are provided.
AddedPreferenceCompat#setChecked(Preference, boolean)helper method.
0.1.2 Deprecated
- Czech strings
SeekBarinSeekBarDialogActivityusesColorFilterto match theme
0.1.1 Deprecated
- Initial release
- Backported material style and icon capability for
Preferencechildren - Backported
SwitchPreference - Material styled
RingtonePreferencepicker dialog/activity
- SwitchPreference does not animate its SwitchCompat widget when clicked.
- MultiSelectListPreference items may be incorrectly tinted on Android 2.
- SeekBarPreference's SeekBar may appear in disabled state until clicked on Android 2.
- Why are some of your classes in
android.support.v7packages?- I'm using their package private features to achieve consistent results.
Most of this library is straight up pillaged latest SDK mixed with heavy reliance on appcompat-v7. Since version 0.5.0 the same applies to preference-v7. Kudos to the people who create and maintain these!









