gpt4 book ai didi

android - 如何在Android中更改 "MaterialDatePicker"的主题?

转载 作者:行者123 更新时间:2023-12-04 23:38:51 24 4
gpt4 key购买 nike

我用过 Material 日期选择器 为了选择一个日期,我也完成了这项任务,但是 我无法更改主题的标题 & 按钮。

        MaterialDatePicker.Builder builder;
MaterialDatePicker materialDatePicker;

long today = MaterialDatePicker.todayInUtcMilliseconds();
CalendarConstraints.Builder con = new CalendarConstraints.Builder();
con.setValidator(DateValidatorPointForward.now());
builder.setSelection(today);
builder.setCalendarConstraints(con.build());

materialDatePicker = builder.build();

findViewById(R.id.startCalender).setOnClickListener(v ->
materialDatePicker.show(getSupportFragmentManager(), builder.toString())
);

materialDatePicker.addOnPositiveButtonClickListener(selection ->
Toast.makeText(this, materialDatePicker.getHeaderText(),
Toast.LENGTH_SHORT).show());

Screenshot attached

最佳答案

你有不同的选择。
您可以使用:

builder.setTheme(R.style.MaterialCalendarTheme);

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

或者你可以使用类似的东西:
  <style name="MaterialCalendarTheme" parent="ThemeOverlay.MaterialComponents.MaterialCalendar">

<!-- Header panel -->
<item name="materialCalendarHeaderLayout">@style/MaterialCalendar.HeaderLayout1</item>
<!-- Buttons -->
<item name="buttonBarPositiveButtonStyle">@style/TextButton.Dialog1</item>
<item name="buttonBarNegativeButtonStyle">@style/TextButton.Dialog1</item>
</style>
<style name="MaterialCalendar.HeaderLayout1" parent="Widget.MaterialComponents.MaterialCalendar.HeaderLayout">
<!--<item name="android:background">?attr/colorPrimary</item>-->
<item name="android:background">@color/primaryLightColor</item>
</style>
<style name="TextButton.Dialog1" parent="Widget.MaterialComponents.Button.TextButton.Dialog">
<item name="android:textColor">@color/white</item>
<item name="backgroundTint">@color/primaryDarkColor</item>
</style>

enter image description here

关于android - 如何在Android中更改 "MaterialDatePicker"的主题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62086854/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com