Android時間選擇器:SlideDateTimePicker

jopen 9年前發布 | 39K 次閱讀 Android開發 移動開發 SlideDateTimePicker

SlideDateTimePicker實現時間選擇器,可以選擇年月日小時分鐘。

Setup

To add this library to your project, add the following to yourbuild.gradle:

dependencies {
    compile project(':slideDateTimePicker')
}

How to Use

(See SampleActivity for a more complete example)

First create a listener object:

private SlideDateTimeListener listener = new SlideDateTimeListener() {

    @Override
    public void onDateTimeSet(Date date)
    {
        // Do something with the date. This Date object contains
        // the date and time that the user has selected.
    }

    @Override
    public void onDateTimeCancel()
    {
        // Overriding onDateTimeCancel() is optional.
    }
};

Then pass the listener into the builder and show the dialog:

new SlideDateTimePicker.Builder(getSupportFragmentManager())
    .setListener(listener)
    .setInitialDate(new Date())
    .build()
    .show();

Note that theDateobject that you pass in to.setInitialDate()should contain both the date and time that you wish to initially display.

To set the minimum date to display:

.setMinDate(date)

To set the maximum date to display:

.setMaxDate(date)

The default time format is the current device's default, but you can force a 24-hour or 12-hour time format:

To force 24-hour time:

.setIs24HourTime(true)

To force 12-hour time:

.setIs24HourTime(false)

The default theme is Holo Light, but you can specify either Holo Light or Dark explicitly:

.setTheme(SlideDateTimePicker.HOLO_LIGHT)

or

.setTheme(SlideDateTimePicker.HOLO_DARK)

To specify the color for the sliding tab underline (indicator):

.setIndicatorColor(Color.parseColor("#FF0000"))

To specify the color of the horizontal divider lines in the DatePicker and TimePicker: You can also set a custom color for the horizontal divider lines in the DatePicker and TimePicker, but for this you have to paste your own version of selection_divider.9.png into the the library's drawable-xxxx folders that has your desired color. To do this, open selection_divider.9.png in a graphics editor, change the color, then paste your new files into the drawable-xxxx folders.

項目主頁:http://www.baiduhome.net/lib/view/home/1428475325760

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!