如何合并 android 5 DatePicker 与 DataPicker 底层 API
How to merge android 5 DatePicker with DataPicker lower APIs
我在 Android Lollipop 上使用 DatePickerDialog(方法 openCalendarLollipop),对于较低版本的日历,我使用第二种方法。
我对较低的日历使用第二种方法,因为如果单击取消按钮对话框,例如。 API 15个新的日期设置,但不应该点击“设置”。
我怎么写一种方式?
我用Activity类
第一种方法
public void openCalendarLollipop(View v){
DatePickerDialog datePickerDialog;
datePickerDialog = new DatePickerDialog(this, new
DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { }
},y,m,d);
datePickerDialog.getDatePicker().setMaxDate(c.getTimeInMillis());
datePickerDialog.show();
}
第二种方法
public void openCalendar(View v){
DatePickerDialog datePickerDialog;
datePickerDialog = new DatePickerDialog(this, new
DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
}
},y,m,d));
datePickerDialog.setButton(DialogInterface.BUTTON_POSITIVE, "OK", new
DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
datePickerDialog.getDatePicker().setMaxDate(c.getTimeInMillis()+10000);
datePickerDialog.show();
}
您可以简单地使用这个 Material 日期时间选择器库,它对我有用
我在 Android Lollipop 上使用 DatePickerDialog(方法 openCalendarLollipop),对于较低版本的日历,我使用第二种方法。
我对较低的日历使用第二种方法,因为如果单击取消按钮对话框,例如。 API 15个新的日期设置,但不应该点击“设置”。
我怎么写一种方式?
我用Activity类
第一种方法
public void openCalendarLollipop(View v){
DatePickerDialog datePickerDialog;
datePickerDialog = new DatePickerDialog(this, new
DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { }
},y,m,d);
datePickerDialog.getDatePicker().setMaxDate(c.getTimeInMillis());
datePickerDialog.show();
}
第二种方法
public void openCalendar(View v){
DatePickerDialog datePickerDialog;
datePickerDialog = new DatePickerDialog(this, new
DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
}
},y,m,d));
datePickerDialog.setButton(DialogInterface.BUTTON_POSITIVE, "OK", new
DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
datePickerDialog.getDatePicker().setMaxDate(c.getTimeInMillis()+10000);
datePickerDialog.show();
}
您可以简单地使用这个 Material 日期时间选择器库,它对我有用