微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

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

我正在使用 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>

My Dialog

解决方法

您可以使用:

builder.setTheme(R.style.MaterialCalendarTheme)

然后定义:

  <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>

enter image description here

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?