答案 0 :(得分:8)
根据您的设计自定义,创建一个可绘制的文件:
case R.id.ll_date:
showDialog(999);
break;
And Dialog is
@Override
protected Dialog onCreateDialog(int id) {
if (id == 999) {
DatePickerDialog datePickerDialog = new DatePickerDialog(mActivity, myDateListener, currYear, currMonth, currDay);
return new DatePickerDialog(this, myDateListener, currYear, currMonth, currDay);
}
return null;
}
private DatePickerDialog.OnDateSetListener myDateListener = new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker arg0, int year, int month, int day) {
Calendar selectedCal = Calendar.getInstance();
selectedCal.set(year, month, day);
DateFormat df = new SimpleDateFormat("MM/dd/yyyy", new Locale("en_US"));
String date = df.format(new Date());
String selectedDate = df.format(selectedCal.getTime());
try {
Date current = df.parse(date);
Date selected = df.parse(selectedDate);
Log.print("Date =================== " + day);
if (selected.before(current)) {
showSnackbar(txtDate, getString(R.string.alert_can_not_able_previous_date));
} else {
int month1 = month + 1;
String Date = (month1 < 10 ? ("0" + month1) : (month1)) + "/" + (day < 10 ? ("0" + day) : (day)) + "/" + year;
txtDate.setText(Date);
}
} catch (ParseException e) {
e.printStackTrace();
}
}
};
并设置为布局的背景