Coder Social home page Coder Social logo

monthyearpicker's Introduction

MonthYearPicker

Fancy year and month picker library for your android app

How to use?

Maven

<dependency>
  <groupId>com.github.twinkle942910</groupId>
  <artifactId>monthyearpicker</artifactId>
  <version>0.0.1</version>
  <type>aar</type>
</dependency>

Gradle

dependencies {
    compile 'com.github.twinkle942910:monthyearpicker:0.0.1'
}

Demonstration

And you can pick a year You can pick a month

You can simply create your dialog in code, using next lines

Calendar calendar = Calendar.getInstance();
calendar.set(2010,01,01);

YearMonthPickerDialog yearMonthPickerDialog = new YearMonthPickerDialog(this, calendar, new YearMonthPickerDialog.OnDateSetListener() {
            @Override
            public void onYearMonthSet(int year, int month) {
                Calendar calendar = Calendar.getInstance();
                calendar.set(Calendar.YEAR, year);
                calendar.set(Calendar.MONTH, month);

                SimpleDateFormat dateFormat = new SimpleDateFormat("MMMM yyyy");

                yearMonth.setText(dateFormat.format(calendar.getTime()));
            }
        });

1st argument - Context.

2nd - Calendar.

3nd - Date set listener.

And after this just show it whenever you need it to appear.

yearMonthPickerDialog.show();

If you want to add your style then add themeId to the constructor as a third argument

for exemple:

Add your custom style to android resources

   <!-- Dialog default theme. -->
    <style name="MyDialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert">
        <item name="colorControlNormal">@android:color/white</item>
        <item name="colorControlActivated">@color/colorPrimary</item>
        <item name="textColorAlertDialogListItem">@android:color/white</item>
        <item name="colorAccent">@color/colorPrimary</item>
        <item name="android:textColorPrimary">@android:color/black</item>
        <item name="android:windowBackground">@drawable/dialog_background</item>
    </style>

It would add colors to the controls and text. Then add a content drawable for backgound. Example:

<?xml version="1.0" encoding="utf-8"?>

<inset xmlns:android="http://schemas.android.com/apk/res/android"
    android:insetLeft="16dp"
    android:insetTop="16dp"
    android:insetRight="16dp"
    android:insetBottom="16dp">

    <shape android:shape="rectangle">
        <corners android:radius="2dp" />
        <solid android:color="@color/colorMainBackground" />
    </shape>

</inset>

use example : R.style.MyDialogTheme

And you will have your custom theme applied.

Customizing dialog title

If you want to change title text color, then add a int color value as a 4th constructor parameter.

use example : R.color.MyTextTitleColor

Also, if you want to change color of title view, you have to change you main theme primary color, because it depends on it's value.

Set a custom year range

If you want the displayed values of year vary within a range, you have to set the first (min) and the last (max) year:

yearMonthPickerDialog.setMinYear(2000);
yearMonthPickerDialog.setMaxYear(2020);

Check demonstraction project for more details.

monthyearpicker's People

Contributors

brunolimam avatar duchuyctlk avatar kukadiajayesh avatar twinkle942910 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.