Giter Site home page Giter Site logo

lhfazry / materialnumberpicker Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kasualbusiness/materialnumberpicker

0.0 2.0 0.0 421 KB

A customizable Android NumberPicker that is inspired from the Material Design Guidelines

License: Apache License 2.0

Java 100.00%

materialnumberpicker's Introduction

MaterialNumberPicker

This library intends to give you more flexibility than the Holo NumberPicker that only comes with two themes for customization.

As many Android developers complained about this component since it was released, this library allows you to access some most wanted private attributes through reflection so that you could easily customize your NumberPicker. This lets you get closer from the MaterialDesign guidelines!

Finally, we built on top of it a builder pattern so you can easily create your MaterialNumberPicker from XML or programmatically.

alt tag

Download

MaterialNumberPicker requires at minimum Android 3.0, same as the native NumberPicker.

Gradle:

compile 'biz.kasual:materialnumberpicker:1.2.1'

Maven:

<dependency>
  <groupId>biz.kasual</groupId>
  <artifactId>materialnumberpicker</artifactId>
  <version>1.2.1</version>
  <type>aar</type>
</dependency>

Eclipse: materialnumberpicker-1.2.1.aar

Usage

You can either define your MaterialNumberPicker via XML or programmatically :

<biz.kasual.materialnumberpicker.MaterialNumberPicker
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:npMinValue="1"
        app:npMaxValue="50"
        app:npDefaultValue="10"
        app:npBackgroundColor="@color/colorAccent"
        app:npSeparatorColor="@color/colorAccent"
        app:npTextColor="@color/colorPrimary"
        app:npTextSize="25sp"/>
MaterialNumberPicker numberPicker = new MaterialNumberPicker.Builder(context)
                .minValue(1)
                .maxValue(10)
                .defaultValue(1)
                .backgroundColor(Color.WHITE)
                .separatorColor(Color.TRANSPARENT)
                .textColor(Color.BLACK)
                .textSize(20)
                .enableFocusability(false)
                .wrapSelectorWheel(true)
                .build();

The latter option only builds the picker for you. It is up to you how you want to display the picker. You can as well insert it in any ViewGroup or inside an AlertDialog as a custom view.

new AlertDialog.Builder(this)
                .setTitle(yourTitle)
                .setView(numberPicker)
                .setPositiveButton(getString(android.R.string.ok), new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Snackbar.make(findViewById(R.id.your_container), "You picked : " + numberPicker.getValue(), Snackbar.LENGTH_LONG).show();
                    }
                })
                .show();
```

By default there is no `NumberPicker.Formatter` when you build your `MaterialNumberPicker` but you can easily attach one to it using the `formatter` builder proprety.

## License

```
Copyright 2015 Kasual Business.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
```

materialnumberpicker's People

Contributors

stephenvinouze avatar ravidsrk avatar

Watchers

James Cloos avatar Lhuqita Fazry 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.