在我的片段中,我创建了一个DatepickerDialog
。现在我想以编程方式更改按钮的背景颜色。我该怎么做?
您可以从对话框中获取按钮并使用getButton()
修改其属性。请参阅下面的示例。调用.show()
后获取按钮,否则会给出null
。
final Calendar c = Calendar.getInstance();
int mYear = c.get(Calendar.YEAR);
int mMonth = c.get(Calendar.MONTH);
int mDay = c.get(Calendar.DAY_OF_MONTH);
DatePickerDialog datePickerDialog = new DatePickerDialog(ConstarintsActivity.this,
(view, year, monthOfYear, dayOfMonth) -> {
}, mYear, mMonth, mDay);
datePickerDialog.show();
datePickerDialog.getButton(DatePickerDialog.BUTTON_NEGATIVE).setTextColor(Color.GREEN);