1

In my fragment I create a DatepickerDialog. Now I want to change the background color of the buttons programmatically. How can I do that?

dudi
  • 5,523
  • 4
  • 28
  • 57
  • what buttons are you talking about. are you looking for something similar to this https://stackoverflow.com/questions/28738089/change-datepicker-dialog-color-for-android-5-0/28738461? – Raghunandan Aug 15 '19 at 07:41

1 Answers1

1

You can get the Button from Dialog and modify it attributes using getButton(). See the example below. Get the button after calling .show(), otherwise it will give a 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);
hugo
  • 3,067
  • 2
  • 12
  • 22
Arsen
  • 71
  • 5