Search code examples
androidmaterial-designandroid-datepickermaterial-componentsmaterial-components-android

MaterialDatePicker : how to set custom today


I want to set custom today to the MaterialDatePicker. But it getting the system date by default. Any idea?


Solution

  • Too long for a comment. This answer doesn't solve your question but just explains why it is not possible to do it.

    Currently (1.1.0-beta02 and 1.2.0-alpha02) you can't customize the value of the today.
    In the adapter used by the MaterialDatePicker you can check:

    if (UtcDates.getTodayCalendar().getTimeInMillis() == date) {
        calendarStyle.todayDay.styleItem(day);
        //..
      } else {
        calendarStyle.day.styleItem(day);
        //..
      }
    

    You can customize the style used by the Day.Today.

     <style name="CustomThemeOverlay.MaterialComponents.MaterialCalendar"
           parent="ThemeOverlay.MaterialComponents.MaterialCalendar" >
       <item name="materialCalendarStyle">@style/CustomWidget_MaterialCalendar</item>
     </style>
    
     <style name="CustomWidget_MaterialCalendar" parent="Widget.MaterialComponents.MaterialCalendar">
        <item name="dayTodayStyle">@style/CustomWidget_DayToday</item>
      </style>
    
      <style name="CustomWidget_DayToday" parent="Widget.MaterialComponents.MaterialCalendar.Day.Today">
         <item name="itemTextColor">@color/...</item>
         <item name="itemStrokeColor">@color/...</item>
      </style>