BottomSheetPickers 各种时间日历
来源:互联网 发布:设计方案优化措施 编辑:程序博客网 时间:2024/06/16 22:58
BottomSheetPickers
![收藏,GitHub 同步 Star](http://p.codekk.com/images/icon/ic_favorite_white.png)
[ ] (https://bintray.com/philliphsu/maven/bottom-sheet-pickers/_latestVersion)
BottomSheetPickers is a library of new date and time pickers for Android, supporting API level 14 and up.
Date Picker
Time Pickers
Number Pad
Grid Picker
Installation
Add the following dependency to your module's build.gradle
:
dependencies { compile 'com.philliphsu:bottomsheetpickers:2.0.0'}
Usage
You must be using a android.support.v4.app.FragmentActivity
or android.support.v4.app.Fragment
. The pickers are indirect subclasses of android.support.v4.app.DialogFragment
.
Implement callbacks
To retrieve the date or time set in the pickers, implement an appropriate callback interface.
com.philliphsu.bottomsheetpickers.date.DatePickerDialog.OnDateSetListener
BottomSheetTimePickerDialog.OnTimeSetListener
@Overridepublic void onDateSet(DatePickerDialog dialog, int year, int monthOfYear, int dayOfMonth) { Calendar cal = new java.util.GregorianCalendar(); cal.set(Calendar.YEAR, year); cal.set(Calendar.MONTH, monthOfYear); cal.set(Calendar.DAY_OF_MONTH, dayOfMonth); mText.setText("Date set: " + DateFormat.getDateFormat(this).format(cal.getTime()));}@Overridepublic void onTimeSet(ViewGroup viewGroup, int hourOfDay, int minute) { Calendar cal = new java.util.GregorianCalendar(); cal.set(Calendar.HOUR_OF_DAY, hourOfDay); cal.set(Calendar.MINUTE, minute); mText.setText("Time set: " + DateFormat.getTimeFormat(this).format(cal.getTime()));}
Create your desired picker
Calendar now = Calendar.getInstance();BottomSheetDatePickerDialog date = BottomSheetDatePickerDialog.newInstance( MainActivity.this, now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH));NumberPadTimePickerDialog pad = NumberPadTimePickerDialog.newInstance(MainActivity.this);GridTimePickerDialog grid = GridTimePickerDialog.newInstance( MainActivity.this, now.get(Calendar.HOUR_OF_DAY), now.get(Calendar.MINUTE), DateFormat.is24HourFormat(MainActivity.this));
Show the dialog
Pass in a android.support.v4.app.FragmentManager
to the dialog's show()
.
// For a `android.support.v4.app.FragmentActivity`:dialog.show(getSupportFragmentManager(), TAG);// For a `android.support.v4.app.Fragment`:dialog.show(getFragmentManager(), TAG);
NOTE: Currently,
BottomSheetDatePickerDialog
cannot be dismissed by swiping the sheet down. This is to allow vertical swiping to scroll the date picker. Touching outside of the sheet also does not dismiss it. It is dismissed normally when you confirm your date selection.
Theming
The pickers automatically use your current theme's colorAccent
defined in your styles.xml
.
You can specify whether to use a light (default) or dark theme:
- in code with the dialog's
setThemeDark(boolean dark)
method. Call this beforeshow()
ing the dialog. - in
styles.xml
by specifying a boolean value for the attributethemeDark
in your theme.
<item name="themeDark">true</item>
NOTE:
setThemeDark(boolean dark)
overwrites the value specified in XML.
Attribution
This library is based on code from the following AOSP repositories:
- https://android.googlesource.com/platform/frameworks/opt/datetimepicker
- https://android.googlesource.com/platform/packages/apps/Calculator
- BottomSheetPickers 各种时间日历
- 时间日历
- 日历时间
- 各种日历控件
- 各种杂项组件(3)之--CalendarView(日历视图)、DatePicker/TimePicker(日期、时间选择器)、NumberPicker(数值选择器)
- javascript日历时间控件
- javascript日历时间控件
- 日历时间控件
- 数码电子日历时间
- 日历时间加减法
- C++ 获取日历时间
- Android 时间日历
- 日历时间控件--My97DatePicker
- 时间——日历
- iOS:日历和时间
- 时间日历:Date、Calendar
- 日历&时间&日期
- h5时间日历
- 06上机练习1
- JADX反编译软件使用
- Centos7 下 Nagios 的安装
- Redis有序集合命令ZREMRANGEBYLEX详解与应用
- JavaEE面试注意事项
- BottomSheetPickers 各种时间日历
- 在配置内核时输入:make menuconfig
- unity 资源加载框架设计
- centos6.5下如何把python2.6.6升级到2.7
- mvc view 获取数据库html标签
- linux 守护进程与用&结尾的后台运行程序有什么区别
- 文章收集
- Rexxar 是一个针对移动端的混合开发框架。
- measure screen dp