项目作者: ycuwq

项目描述 :
Android DatePicker
高级语言: Java
项目地址: git://github.com/ycuwq/DatePicker.git
创建时间: 2017-12-12T03:16:29Z
项目社区:https://github.com/ycuwq/DatePicker

开源协议:MIT License

下载


DatePicker

MIT

Android date picker widget.

screen

Repo Wiki

简体中文说明
实现思路文档

Import

Add it in your root build.gradle at the end of repositories:

  1. allprojects {
  2. repositories {
  3. maven { url 'https://jitpack.io' }
  4. }
  5. }

Add the dependency to your app modules:

  1. dependencies {
  2. implementation 'com.github.ycuwq:DatePicker:latest-version'
  3. }

Usage

  1. <com.ycuwq.datepicker.date.DatePicker
  2. android:id="@+id/datePicker"
  3. android:layout_width="match_parent"
  4. android:layout_height="wrap_content"></com.ycuwq.datepicker.date.DatePicker>

Show Dialog

screen

DatePickerDialogFragmentextends DialogFragment ,for example:

  1. DatePickerDialogFragment datePickerDialogFragment = new DatePickerDialogFragment();
  2. datePickerDialogFragment.setOnDateChooseListener(...);
  3. datePickerDialogFragment.show(getSupportFragmentManager(), "DatePickerDialogFragment");

If you want to customize the style ,for example::

  1. public class MyDatePickerDialogFragment extends DatePickerDialogFragment {
  2. @Override
  3. protected void initChild() {
  4. super.initChild();
  5. mCancelButton.setTextSize(mCancelButton.getTextSize() + 5);
  6. mDecideButton.setTextSize(mDecideButton.getTextSize() + 5);
  7. mDatePicker.setShowCurtain(false);
  8. }
  9. }

Format date

You can set the format of the date by setDataFormat().

  1. double[] limits = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
  2. String[] formats = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sept", "Oct", "Nov", "Dec" };
  3. ChoiceFormat format = new ChoiceFormat(limits, formats);
  4. datePicker.getMonthPicker().setDataFormat(format);

Custom layout

You can custom layout by extends DatePicker and override getLayoutId() method, return your layout
id. You can see CustomDatePicker in demo.

License

  1. MIT License
  2. Copyright (c) 2018 ycuwq
  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in all
  10. copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  17. SOFTWARE.