Material Preferences
A beautiful and extensible API for bulding preferences screen.
? Installation
Add this in app's build.gradle
file:
⭐ Features
- Convenient and extensible DSL
- Flexible appearance settings
- Unified view on Lollipop and Pre-Lollipop
- Ability to use custom storage
- Default prefs values
- Light and dark themes
? Usage
To start using the library you need to do 3 simple steps:
- Add
MaterialPreferencesView
in your layout - Provide preferences storage:
3.1 Default storage -DefaultPreferencesStorage
3.1 Any custom storage which implements thePreferencesStorage
interface - Build prefs screen via MaterialPrefs DSL
If want to use DefaultPreferencesStorage
you have to provide initial values through DefaultValuesContainer
.
Step 1
Place the MaterialPreferencesView
in your layout:
Step 2
Create prefs storage and provide initial values:
Step 3
Add pref items via MaterialPrefs DSL:
? Documentation
The library includes 4 modules:
- core - contains main code: simple prefs, checkbox, switch
- dialogs - dialogs prefs: single and multiple choice
- date-time - date and time pickers
- color-picker - color picker
Three last modules based on Material Dialogs library.
Core
Simple preference:
Switch:
Checkbox:
Label preference:
Dialogs
Single Choice:
Multi Choice:
Text Input:
DateTime
Date picker:
Time picker:
Date and picker:
ColorPicker
Custom preference item
To create custom preference item you have to do 3 steps:
Step 1:
Create preference view class inherited from PreferenceView
or BasePreferenceView
.
If your view inherited from BasePreferenceView
you have to implement createValueView
method:
Step 2:
Create preference class inherited from Preference
or BasePreference
and implement 3 methods:
Third generic parameter of BasePreference
is a type of data, that will be save in the preferences, so it must be one of the following types:
- String
- Int
- Long
- Float
- Boolean
Step 3:
Create extension method for MaterialSettings
: