我想将日期选择器视图更改为标准模式
从
至
我的代码是
dateOfBirthET = (EditText) findViewById(R.id.dateOfBirth);
//setting dateSetListener
final DatePickerDialog.OnDateSetListener date = new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
// TODO Auto-generated method stub
myCalendar.set(Calendar.YEAR, year);
myCalendar.set(Calendar.MONTH, monthOfYear);
myCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
updateLabel();
updateLabelToSave();
}
};
//setting onClickListener on setDate
dateOfBirthET.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
DatePickerDialog dpd = new DatePickerDialog(RegisterActivity.this, date,
myCalendar.get(Calendar.YEAR), myCalendar.get(Calendar.MONTH),
myCalendar.get(Calendar.DAY_OF_MONTH));
//setting maxDate on tempCal
long maxDate = new Date().getTime();
tempCal.setTimeInMillis(maxDate);
tempCal.set(Calendar.YEAR, tempCal.get(Calendar.YEAR) - 16);
dpd.getDatePicker().setMaxDate(tempCal.getTimeInMillis());
dpd.show();
}
});
}
我也尝试了这段代码,但没有工作
dpd.getDatePicker().setCalendarViewShown(false);
解决方法:
您只需在创建DatePickerDialog实例时更改所需的主题
DatePickerDialog dpd = new DatePickerDialog(RegisterActivity.this, android.R.style.Theme_Holo_Dialog ,date,
myCalendar.get(Calendar.YEAR), myCalendar.get(Calendar.MONTH),
myCalendar.get(Calendar.DAY_OF_MONTH));
为我工作测试了android 6.0 marshmallow.