我有以下代码:
private void openDatePicker() {
MaterialDatePicker picker =
MaterialDatePicker.Builder.datePicker()
.setTitleText("Select date")
.setTheme(R.style.DatePickerTheme)
.setSelection(MaterialDatePicker.todayInUtcMilliseconds())
.build();
picker.show(getParentFragmentManager(),"tag");
picker.addOnPositiveButtonClickListener(new MaterialPickerOnPositiveButtonClickListener() {
@Override
public void onPositiveButtonClick(Object selection) {
try {
mtnRecDate.setText(sdf.format(selection));
} catch (Exception e) {
FancyToast.makeText(getContext(),"Setting Date failed!",FancyToast.LENGTH_LONG,FancyToast.ERROR,false).show();
}
}
});
}
风格:
<!-- Picker styles and themes. -->
<style name="DatePickerTheme" parent="@style/ThemeOverlay.MaterialComponents.MaterialCalendar">
<item name="materialCalendarStyle">@style/Widget.MaterialComponents.MaterialCalendar</item>
<item name="materialCalendarFullscreenTheme">@style/ThemeOverlay.MaterialComponents.MaterialCalendar.Fullscreen</item>
<item name="materialCalendarTheme">@style/Widget.MaterialComponents.MaterialCalendar.MonthNavigationButton</item>
<item name="materialCalendarMonthNavigationButton">@style/Widget.MaterialComponents.MaterialCalendar.MonthNavigationButton</item>
</style>
我试图隐藏年份选项:
它应该看起来更像这样:
我怎样才能做到这一点。我尝试更改样式主题(见上文),但没有任何结果。