Material DateRangePicker设置默认范围
Material DateRangePicker set up a default range
我想在我的 DateRangePicker
中选择一个默认范围。我怎样才能得到它?
我现在的代码:
CalendarConstraints.Builder constraintBuilder = new CalendarConstraints.Builder();
constraintBuilder.setValidator(DateValidatorPointForward.now());
MaterialDatePicker.Builder builder = MaterialDatePicker.Builder.dateRangePicker();
builder.setCalendarConstraints(constraintBuilder.build());
final MaterialDatePicker materialDatePicker = builder.build();
imageDate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
materialDatePicker.show(getSupportFragmentManager(), "TAG");
}
});
请使用MaterialDatePicker.Builder.setSelection()
方法。下面的代码用于将今天设置为开始日期和结束日期:
在Java中:
Calendar now = Calendar.getInstance()
MaterialDatePicker.Builder builder = MaterialDatePicker.Builder.dateRangePicker();
builder.setSelection(androidx.core.util.Pair(now.getTimeInMillis(), now.getTimeInMillis())
在 Kotlin 中
val now = Calendar.getInstance()
val builder = MaterialDatePicker.Builder.dateRangePicker()
builder.setSelection(androidx.core.util.Pair(now.timeInMillis, now.timeInMillis))
我想在我的 DateRangePicker
中选择一个默认范围。我怎样才能得到它?
我现在的代码:
CalendarConstraints.Builder constraintBuilder = new CalendarConstraints.Builder();
constraintBuilder.setValidator(DateValidatorPointForward.now());
MaterialDatePicker.Builder builder = MaterialDatePicker.Builder.dateRangePicker();
builder.setCalendarConstraints(constraintBuilder.build());
final MaterialDatePicker materialDatePicker = builder.build();
imageDate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
materialDatePicker.show(getSupportFragmentManager(), "TAG");
}
});
请使用MaterialDatePicker.Builder.setSelection()
方法。下面的代码用于将今天设置为开始日期和结束日期:
在Java中:
Calendar now = Calendar.getInstance()
MaterialDatePicker.Builder builder = MaterialDatePicker.Builder.dateRangePicker();
builder.setSelection(androidx.core.util.Pair(now.getTimeInMillis(), now.getTimeInMillis())
在 Kotlin 中
val now = Calendar.getInstance()
val builder = MaterialDatePicker.Builder.dateRangePicker()
builder.setSelection(androidx.core.util.Pair(now.timeInMillis, now.timeInMillis))