如何自定义 material 组件的日期范围选择器的颜色和其他内容?

how to customize colors and other things of the date range picker of material component?

如何仅在日期范围选择器中更改 header 的颜色,我搜索并没有找到确切的方法,我只知道如何通过更改日期范围选择器的颜色来更改所有日期范围选择器的颜色colorPrimary,这将更改所有 header 和选定日期的颜色,我只想更改 header 颜色

另外,如果有办法更改标题文本的大小,我知道我们可以更改标题,但我们可以更改标题大小吗?

这是我尝试过的风格

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/shamrock_green</item>
    <item name="colorPrimaryDark">@color/shamrock_green_dark</item>
    <item name="colorAccent">@color/shamrock_green</item>
    <item name="colorButtonNormal">@color/shamrock_green</item>
    <item name="colorOnSecondary">@color/white</item>
    <item name="colorOnSurface">@android:color/transparent</item>
    <item name="bottomSheetDialogTheme">@style/AppBottomSheetDialogTheme</item>
    <item name="materialCalendarFullscreenTheme">@style/CustomThemeOverlay_MaterialCalendar_Fullscreen</item>

</style>

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="colorOnSurface">@android:color/black</item>
    <item name="colorPrimary">@color/black</item>
</style>

<style name="CustomThemeOverlay_MaterialCalendar_Fullscreen"
    parent="@style/ThemeOverlay.MaterialComponents.MaterialCalendar.Fullscreen">
    <item name="materialCalendarStyle">@style/Custom_MaterialCalendar.Fullscreen</item>
</style>
<style name="Custom_MaterialCalendar.Fullscreen"
    parent="@style/Widget.MaterialComponents.MaterialCalendar.Fullscreen">
    <item name="android:windowFullscreen">false</item>
    <item name="android:headerBackground">@color/shamrock_green</item>
</style>

<style name="ThemeMaterialCalendarButton" parent="Widget.MaterialComponents.Button.TextButton.Dialog">
    <item name="android:textColor">@color/shamrock_green</item>
</style>

<style name="ThemeMaterialCalendarTextButton" parent="Widget.MaterialComponents.Button.TextButton.Dialog.Flush">
    <item name="android:textColor">@color/shamrock_green</item>
    <item name="iconTint">@color/shamrock_green</item>
</style>

<style name="AppTheme.FullScreen" parent="@style/Theme.AppCompat">
    <item name="windowNoTitle">true</item>
    <item name="android:windowFullscreen">true</item>
</style>


</resources>

现在有效的是它显示为对话框而不是我想要的全屏,但文本和背景颜色没有变化,更改颜色的唯一方法是更改​​颜色,如 colorPrimary,这些颜色将影响所有应用程序

您可以使用主题覆盖:

MaterialDatePicker.Builder<Pair<Long, Long>> builderRange =
        MaterialDatePicker.Builder.dateRangePicker();
builderRange.setTheme(R.style.CustomMaterialCalendarTheme);

与:

  <style name="CustomMaterialCalendarTheme" parent="ThemeOverlay.MaterialComponents.MaterialCalendar">
       <!-- Header Layout -->
       <item name="materialCalendarHeaderLayout">@style/customHeaderLayout</item>
       <!-- Header title -->
       <item name="materialCalendarHeaderTitle">@style/customHeaderTitle</item>
       <!-- Header selection title -->
       <item name="materialCalendarHeaderSelection">@style/CustomHeaderSelection</item>
  </style>


   <style name="customHeaderLayout" parent="@style/Widget.MaterialComponents.MaterialCalendar.HeaderLayout">
      <item name="android:background">@color/.....</item>
   </style>

    <style name="customHeaderTitle" parent="@style/Widget.MaterialComponents.MaterialCalendar.HeaderTitle">
      <item name="android:textAppearance">@style/customTextAppearance</item>
    </style>

   <style name="customTextAppearance" parent="@style/TextAppearance.MaterialComponents.Overline">
      <item name="android:textSize">xxsp</item>
   </style>

   <style name="CustomHeaderSelection" parent="Widget.MaterialComponents.MaterialCalendar.HeaderSelection">
      <item name="android:textSize">xxsp</item>
   </style>