Skip to content
项目

关于

Android DatePicker

网站与应用开发

这些数字如何统计

实测星标增长

24小时
0
7天
0
15天
0
1个月
正在收集历史

各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。

README-CN.md

原文

DatePicker

Android 日期选择器控件。

screen

Repo Wiki

实现思路文档

引入

根目录加入

allprojects {
    repositories {

        maven { url 'https://jitpack.io' }
    }
}

在 app modules加入依赖:


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

在XML中配置

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

显示弹窗

screen

弹窗继承了 DialogFragment ,使用方式:

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

如果想自定义属性需要继承DialogFragment ,例如:

public class MyDatePickerDialogFragment extends DatePickerDialogFragment {

   @Override
   protected void initChild() {
      super.initChild();
      mCancelButton.setTextSize(mCancelButton.getTextSize() + 5);
      mDecideButton.setTextSize(mDecideButton.getTextSize() + 5);
      mDatePicker.setShowCurtain(false);
   }
}

自定义格式化日期

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

自定义布局

继承 DatePicker 重写 DatePicker 的getLayoutId()方法,返回自定义的布局id。可查看demo中的CustomDatePicker

协议

MIT License

Copyright (c) 2018 ycuwq

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

探索相关项目

加载中…