Coder Social home page Coder Social logo

android-materialpreference's Introduction

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.

android-materialpreference's People

Contributors

msutherland4807 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

android-materialpreference's Issues

Changing the color of PreferenceCategory Text

This is what I am currently doing. Problem is I am getting NPE on the onPreferenceClickListener.

I am needing to set the color through code and not a theme. i figured I could just override this method and set the color this way. If I comment out all the listeners then I don't get a NPE and it changes the category text color. But doing it this way is causing the preferences not to be found for some reason

Just something to note. Everything worked just fine before overriding the PreferenceCategory so I know the error isn't somewhere else in my code.

MyPreferenceCategory.Java

import com.jenzz.materialpreference.PreferenceCategory;
import android.widget.TextView;

public class MyPreferenceCategory extends PreferenceCategory {

    public MyPreferenceCategory(Context context) {
        super(context);
    }

    @Override
    protected void onBindView(View view) {
        super.onBindView(view);
        TextView titleView = (TextView) view.findViewById(R.id.title);
        titleView.setTextColor(Color.BLUE);
    }
}

Fragment.java

com.jenzz.materialpreference.Preference installPref = (com.jenzz.materialpreference.Preference) findPreference("install");
installPref.setOnPreferenceClickListener(this);

Layout.xml

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:id="@+id/screen">

    <com.my.app.MyPreferenceCategory
        android:title="@string/lbl_installText"
        android:key="installCat">
        <com.jenzz.materialpreference.Preference
            android:title="@string/lbl_install"
            android:key="install" >
        </com.jenzz.materialpreference.Preference>

    </com.my.app.MyPreferenceCategory>
</PreferenceScreen>

Gradle issue

There is an issue while including the gradle into project.It giving the error as not reolved

Switch Preference

snap 2015-03-22 at 11 00 26
I just found out there is no switch preference, should I use the one available in stock or switch to something else? any advice? thanks for your reply in advance

Side-by-side comparison missing

In the readme you wanted to show a side-by-side comparison but the material screenshot is missing. Would be nice to have to be able to compare before using the lib. Thanks!

Anyway to change the margins

The categories and preferences are aligning with each other. I see that is the way the sample app is. But is there anyway to change that? Didn't see any reference for it so I thought I would ask

CheckBoxPreference disableDependentsState not working

As in title, I have my disableDependentsState set to true, so that when my CheckBox is ticked, another pref is disabled, however no matter how I set the attribute, the other pref is always enabled/disabled when CheckBox on/off respectively

I've tried using the source lib and changing line 42 to look in index 2 (which I think is correct anyway) but it still doesn't seem to work

Thanks for the lib!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.