当我创建DatePickerDialog时,我有一种非常奇怪的行为。没有特殊主题或任何自定义,我在白色背景上将所有文本都显示为白色,因此没有显示日期。你可以在这里看到截图:
任何可能出错的想法?
修改的
这里你有我创建对话框的代码,没什么特别的。
Date date = DateUtils.getDateMinusYears(18);
Calendar calendar = new GregorianCalendar();
calendar.setTime(date);
final SimpleDateFormat dateFormatter = new SimpleDateFormat("dd-MM-yyyy", Locale.US);
datePickerDialog = new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener()
{
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth)
{
Calendar newDate = Calendar.getInstance();
newDate.set(year, monthOfYear, dayOfMonth);
mTextDateBirth.setText(dateFormatter.format(newDate.getTime()));
mImgIconDate.setVisibility(View.GONE);
btnDate.setBackgroundResource(R.drawable.global_background_with_border_orange);
}
}, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH));
}
datePickerDialog.show();
答案 0 :(得分:0)
尝试使用颜色
<style name="datepicker" parent="Theme.AppCompat.Light.Dialog">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorPrimary</item>
</style>
的java
private int mYear, mMonth, mDay;
final Calendar c = Calendar.getInstance();
mYear = c.get(Calendar.YEAR);
mMonth = c.get(Calendar.MONTH);
mDay = c.get(Calendar.DAY_OF_MONTH);
DatePickerDialog datePickerDialog = new
DatePickerDialog(yourActivity.this, R.style.datepicker,
new DatePickerDialog.OnDateSetListener()
{
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth)
{
youredittext.setText(dayOfMonth + "-" + (monthOfYear + 1) + "-" + year);
}
}, mYear, mMonth, mDay);
datePickerDialog.show();