GithubHelp home page GithubHelp logo

jiubadao / materialpreference Goto Github PK

View Code? Open in Web Editor NEW

This project forked from vorabhai/materialpreference

0.0 2.0 0.0 146 KB

Library to add material designed Preference/Settings screen to an Android App

Home Page: http://codevscolor.com

License: Apache License 2.0

Java 100.00%

materialpreference's Introduction

Material Preference

Android Arsenal CircleCI

Report an issue

This library can be used to implement Material Designed Settings/Preference Screen on Pre-Lollipop devices. (Currently supporting devices upto api 9 )

  • Material Preference Library uses com.android.support:preference-v7:x.x.x support library widgets.
  • Also it includes a color chooser dialog widget, that can be used to select accent color .
  • Header is tinted with selected secondary color.

Demo

On Lollipop :

Demo

On KitKat :

Demo

Light Theme :

Demo

Download

dependencies {
compile 'com.codevscolor.materialpreference:mp:0.2.1'
}

How do I use this library ?

  1. Create one preference xml file inside res/xml folder
  2. Add android.support.v7.preference widgets.
  3. For Preference category, use com.codevscolor.materialpreference.widget.MaterialPreferenceCategory with a title , like :
<com.codevscolor.materialpreference.widget.MaterialPreferenceCategory android:title="Category one">
.........
.........
</com.codevscolor.materialpreference.widget.MaterialPreferenceCategory>
  1. If you want to use color chooser widget,use it with a key,summary and title like
<com.codevscolor.materialpreference.widget.ColorChooserPreference
            android:key="secondary_color_position"
            android:summary="select accent color"
            android:title="secondary color" />
  1. Now create your Preference Activity like
import com.codevscolor.materialpreference.util.MaterialPrefUtil;
import com.codevscolor.materialpreference.activity.MaterialPreferenceActivity;
import com.codevscolor.materialpreference.callback.MaterialPreferenceCallback;

public class SettingsActivity extends MaterialPreferenceActivity implements MaterialPreferenceCallback {

    //initialization of the sdk should be done here
    @Override
    public void init(@Nullable Bundle savedInstanceState) {
        //register this class as listener for preference change
        setPreferenceChangedListener(this);

        //use dark theme or not . Default is light theme
        useDarkTheme(true);

        //set toolbar title
        setToolbarTitle("My Toolbar");

        //set primary color
        setPrimaryColor(MaterialPrefUtil.COLOR_BLUE_GREY);

        //default secondary color for tinting widgets, if no secondary color is used yet
        setDefaultSecondaryColor(this, MaterialPrefUtil.COLOR_BLUE);

        //set application package name and xml resource name of preference
        setAppPackageName("com.exampletest.sampleapplicationsettings");
        //set xml resource name
        setXmlResourceName("settingspreference");

        //optional
        //if you are using color picker, set the key used for color picker in the xml preference
        setColorPickerKey("secondary_color_position");

    }


    /**
     * callback for preference changes
     *
     * @param sharedPreferences
     * @param name
     */
    @Override
    public void onPreferenceSettingsChanged(SharedPreferences sharedPreferences, String name) {
        Toast.makeText(this, "preference with key " + name + " changed", Toast.LENGTH_LONG).show();
    }
}

Compatibility

API level 8 and above

Author

Nandan Kaushik Dutta - @codevscolor on GitHub, personal blog : codevscolor

License

Apache 2.0

materialpreference's People

Contributors

codevscolor avatar

Watchers

James Cloos avatar gopher avatar

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.