Android MaterialDatePicker : How to change color of calendar

Issue

I am trying to change color using style code in XML.
I am not able to change the background color of the calendar.

In the image below I want to change white color area of right side to some custom color of my choice.

Image showing white color, which I want to change

Currently I am using following theme to change color on left side to blue, and some rounded corners.

 <!--Calendar-->
<style name="AppDatePicker" parent="@style/ThemeOverlay.MaterialComponents.MaterialCalendar">
    <item name="colorPrimary">@color/blue_click</item>
    <item name="shapeAppearanceMediumComponent">@style/ShapeAppearance.App.MediumComponent
    </item>
</style>

<style name="ShapeAppearance.App.MediumComponent" parent="ShapeAppearance.MaterialComponents.MediumComponent">
    <item name="cornerSize">16dp</item>
</style>


    long today = MaterialDatePicker.todayInUtcMilliseconds();

    // going back by a week
    long startDate = today - 604800000L;
    long endDate = today;

    // setting available days for a week only
    List<CalendarConstraints.DateValidator> validatorList = new ArrayList<>();
    validatorList.add(DateValidatorPointBackward.now());
    validatorList.add(DateValidatorPointForward.from(startDate));

    CalendarConstraints constraints = new CalendarConstraints.Builder()
            .setStart(startDate)
            .setEnd(endDate)
            .setOpenAt(today)
            .setValidator(CompositeDateValidator.allOf(validatorList))
            .build();

    MaterialDatePicker<Long> selectDate = MaterialDatePicker.Builder
            .datePicker()
            .setCalendarConstraints(constraints)
            .setTheme(R.style.AppDatePicker)
            .setSelection(sharedPref.getSelectedSyncDate())
            .setTitleText("SELECT DATE")
            .build();

    DateFormat dateFormat = new SimpleDateFormat("MM-dd");
    Calendar cal = Calendar.getInstance();
    selectDate.show(getActivity().getSupportFragmentManager(), "DATE_PICKER"); 

Solution

Maybe issue is over here

<style name="ThemeOverlay.App.MaterialCalendar" parent="ThemeOverlay.MaterialComponents.MaterialCalendar">
   <!-- just override the colors used in the default style -->
   <item name="colorOnPrimary">@color/...</item>
   <item name="colorPrimary">@color/...</item>
 </style>

Answered By – Khushbu

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published