1. 程式人生 > >時間選擇器 PickerView

時間選擇器 PickerView

//新增依賴

compile 'com.contrarywind:Android-PickerView:3.2.7'

//程式碼

Calendar selectedDate = Calendar.getInstance();
Calendar startDate = Calendar.getInstance();
Calendar endDate = Calendar.getInstance();
//選擇的起始時間
startDate.set(2017,0,1);

//選擇的結束時間endDate.set(2020,0,1),也可設定為當前日期endDate.get(Calendar.DATE)。
endDate.get(Calendar.DATE);

timePickerView = new TimePickerView.Builder(mContext, new TimePickerView.OnTimeSelectListener() {
    @Override
    public void onTimeSelect(Date date, View v) {
        selctTime  = date.getTime();
      dataBinding.stvCostData.setRightString(TimeUtils.formatDateForPoint(selctTime));
    }
}).setType(new boolean[]{true, true, true, false, false, false})//需要時分秒改為true
        .setLabel("年", "月", "日", "", "", "")
        .isCenterLabel(false)
        .setDividerColor(Color.DKGRAY)
        .setContentSize(21)
        .setDate(selectedDate)
        .setRangDate(startDate, endDate)
        .setDecorView(null).build();