BottomSheetPickers 各种时间日历

BottomSheetPickers

简介:Third-party time pickers for Android.

Download ] (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
@Override
public 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()));
}

@Override
public 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 before show()ing the dialog.
  • in styles.xml by specifying a boolean value for the attribute themeDark 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:

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值