如何更改材质日期选择器对话框的按钮颜色

a_l*_*ody 1 android android-datepicker material-components-android

我正在使用 Material 组件创建 DatePicker。据我了解,colorPrimary用于确定对话框顶部部分的颜色,以及按钮上文本的颜色,特别是CANCELOK

浏览文档,我似乎找不到一种方法来更改底部按钮的颜色?可以这样做吗?

当前代码:

<style name="ThemeOverlay.App.DatePicker" parent="@style/ThemeOverlay.MaterialComponents.MaterialCalendar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorOnPrimary">@android:color/white</item>
    <item name="shapeAppearanceSmallComponent">@style/ShapeAppearance.App.SmallComponent</item>
    <item name="shapeAppearanceMediumComponent">@style/ShapeAppearance.App.MediumComponent
    </item>
    <item name="materialCalendarHeaderTitle">@style/MyHeaderTitle</item>
    <item name="colorOnPrimarySurface">@android:color/white</item>
</style>

<style name="MyHeaderTitle" parent="Widget.MaterialComponents.MaterialCalendar.HeaderTitle">
    <item name="android:textColor">@android:color/white</item>
</style>

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

<style name="ShapeAppearance.App.SmallComponent" parent="ShapeAppearance.MaterialComponents.SmallComponent">
    <item name="android:textSize">24sp</item>
    <item name="cornerSize">16dp</item>
</style>

<style name="ShapeAppearance.App.MediumComponent" parent="ShapeAppearance.MaterialComponents.MediumComponent">
    <item name="android:textSize">30sp</item>
    <item name="cornerSize">16dp</item>
</style>
Run Code Online (Sandbox Code Playgroud)

我的对话

Gab*_*tti 7

您可以使用:

builder.setTheme(R.style.MaterialCalendarTheme)
Run Code Online (Sandbox Code Playgroud)

然后定义:

  <style name="MaterialCalendarTheme" parent="ThemeOverlay.MaterialComponents.MaterialCalendar">

    <!-- Buttons -->
    <item name="buttonBarPositiveButtonStyle">@style/TextButton</item>
    <item name="buttonBarNegativeButtonStyle">@style/TextButton</item>
  </style>
  <style name="TextButton" parent="Widget.MaterialComponents.Button.TextButton.Dialog">
    <item name="android:textColor">@color/...</item>
    <item name="backgroundTint">@color/...</item>
  </style>
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述