本文介绍了如何更改"MaterialDatePicker"的主题;在Android中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经使用 MaterialDatePicker 来选择单个日期&我也已经完成了这项任务,但是我无法更改标题&的主题按钮.
I've used MaterialDatePicker for the purpose of selecting a single date & also I had achieved that task but I cannot change the theme of the header & button.
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());
推荐答案
您有不同的选择.
您可以使用:
You have different options.
You can use:
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>
或者您可以使用类似的内容:
or you can use something like:
<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>
这篇关于如何更改"MaterialDatePicker"的主题;在Android中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!