我在项目中实现了DatePickerDialog,将消息设置为DatePickerDialog。但是,当我运行Project时,消息文本在白色背景上显示。我想更改该消息文本背景的颜色。
Calendar cal = Calendar.getInstance();
final DatePickerDialog datePickerDialog = new DatePickerDialog(ContactDetailsActivity.this, R.style.UserDialog, new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
Log.d("Orignal", "Got clicked");
String date = dayOfMonth + "/" + String.valueOf(month + 1) + "/" + year;
editTextEndDate.setText(date);
}
},
cal.get(Calendar.YEAR),
cal.get(Calendar.MONTH),
cal.get(Calendar.DAY_OF_MONTH));
datePickerDialog.setMessage("Start date");
datePickerDialog.show();
UserDialog
<style name="UserDialog" parent="Theme.AppCompat.Light.Dialog">
<item name="android:background">@color/colorAccent</item>
<item name="android:"></item>
</style>
我想将“结束日期”的背景设置为colorAccent
答案 0 :(得分:0)
在style.xml中设置选择器的颜色
<color name="colorAccent">"#ffffff"< /color>
TextView date;
DatePickerDialog datePickerDialog;
int year;
int month;
int dayOfMonth;
Calendar calendar;
date = findViewById(R.id.tvSelectedDate);
calendar = Calendar.getInstance();
year = calendar.get(Calendar.YEAR);
month = calendar.get(Calendar.MONTH);
dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
datePickerDialog = new DatePickerDialog(MainActivity.this,
new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker datePicker, int year, int month, int day) {
date.setText(day + "/" + (month + 1) + "/" + year);
}
}, year, month, dayOfMonth);
datePickerDialog.getDatePicker().setMinDate(System.currentTimeMillis());
datePickerDialog.show();