如何在DatePickerDialog中更改按钮的背景颜色?

时间:2019-08-15 07:38:52

标签: android datepicker styles android-alertdialog

在片段中,我创建一个DatepickerDialog。现在,我想以编程方式更改按钮的背景色。我该怎么办?

1 个答案:

答案 0 :(得分:1)

您可以从对话框中获取按钮,并使用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);