• This repository has been archived on 16/Jan/2019
  • Stars
    star
    509
  • Rank 86,772 (Top 2 %)
  • Language
    Java
  • License
    MIT License
  • Created almost 10 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

[DEPRECATED] A simple backward-compatible implementation of a Material Design Preference aka settings item

DEPRECATED

Android-MaterialPreference is deprecated. No more development will be taking place.

Use Google's official support libraries instead com.android.support:preference-v7 and com.android.support:preference-v14.

If you need some assistance in building a fully Material Design settings screen, here is a great series of blog articles on this topic:
Building an Android Settings Screen (Part 1) - How to Create and Fix the Overview Screen
Building an Android Settings Screen (Part 2) - How to Create and Fix the Dialogs
Building an Android Settings Screen (Part 3) - How to Create Custom Preferences
Building an Android Settings Screen (Part 4) - How to Use a Custom Layout for the Preference Fragment

Android - MaterialPreference

Screenshots

  • Here's a side-by-side comparison with a native Lollipop preference:

alt text

Usage

In your settings XML file that describes your preferences (must be located in res/xml/ folder) just use the custom implementations like this:

<com.jenzz.materialpreference.PreferenceCategory
  android:title="Material Category">

  <com.jenzz.materialpreference.Preference
    android:title="Material Preference"
    android:summary="Material Summary" />

  <com.jenzz.materialpreference.CheckBoxPreference
    android:title="Material CheckBoxPreference"
    android:summaryOn="Material CheckBox Summary On"
    android:summaryOff="Material CheckBox Summary Off" />

</com.jenzz.materialpreference.PreferenceCategory>

That's it. You can use all the attributes you know from the original preferences.

You're probably wondering why there are only Material Design versions of Preference, PreferenceCategory and CheckBoxPreference. Where are ListPreference, EditTextPreference, etc? I don't use them. Instead I just show a simple Preference and display a Material Design dialog when the user selects it. I highly recommend using the material-dialogs library for that.

Theming

  • On Lollipop, the preference color is derived from the android:colorAccent attribute of your app theme.
  • If you're using AppCompat, it is inherited from the colorAccent attribute.
  • If you want a totally different color for your preferences (why would you?), you can still override it in your app theme like this:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
  <item name="mp_colorAccent">#bada55</item>
</style>

Also note that the Activity hosting your preferences screen must extend ActionBarActivity in order for the CheckBox tinting to work. The easiest solution to accomplish that is to delegate all your preferences logic (including the inflation) to a PreferenceFragment just like it is done in the sample project.

Example

Check out the sample project for an example implementation.

Download

Grab it via Gradle:

compile 'com.jenzz:materialpreference:1.3'

License

This project is licensed under the MIT License.

More Repositories

1

Android-UndoBar

[DEPRECATED] An implementation of Android's Undo Bar as seen in Google's Gmail app.
Java
582
star
2

RxAppState

[DEPRECATED] A simple Android library that monitors app state changes (background / foreground).
Java
195
star
3

ContentProviderHelper

A nice little Android app that helps developers to discover and query content providers.
Java
112
star
4

Android-MultiStateListView

A simple Android ListView that lets you define three states: Loading, Empty & Error
Java
72
star
5

Android-StaticLauncher

An example project of Android annotation processing using Gradle.
Java
38
star
6

Java-PojoBuilder

A Java code generator for the builder pattern using annotation processing
Java
35
star
7

gradle-android-buildconstants-plugin

A Gradle plugin for Android which generates both Java and XML constants as part of the build process.
Groovy
28
star
8

Java-NoOp

Easy no-op Java interface implementations
Java
21
star
9

social-web-search

Search the social web... Find people & posts on Twitter, Facebook and Google+.
13
star
10

.shell_config

A collection of all the stuff I'm using to customize my cmd prompt.
Shell
3
star
11

java-android-utils

A collection of useful utilities, templates and snippets for Java & Android development that I find myself using in many projects.
Java
2
star
12

Android-DemoApp

A simple demo app for an offline-first architecture.
Kotlin
2
star
13

leo-chrome

A simple Chrome extension for the LEO dictionary (http://goo.gl/7eMdg).
JavaScript
1
star
14

RxJava-Tidbits

Tips & Tricks and solutions to common, real-world problems using RxJava
Java
1
star
15

Android-Sandbox

My little sandbox for trying out cool Android stuff.
Java
1
star
16

Android-PeopleNotes

Android app to keep notes about people
Kotlin
1
star
17

TheTVDB-Retrofit

Java API for TheTVDB.com based on Square's Retrofit REST client
Java
1
star