物料日期选择器自定义样式

物料日期选择器自定义样式

本文介绍了物料日期选择器自定义样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将此库中的Google资料用于范围日期选择器

i have used range date picker from google material with this library

这是我的代码

     MaterialDatePicker.Builder<Pair<Long, Long>> builder =
            MaterialDatePicker.Builder.dateRangePicker();

    CalendarConstraints.Builder constraintsBuilder = new CalendarConstraints.Builder();
    builder.setCalendarConstraints(constraintsBuilder.build());
    MaterialDatePicker<Pair<Long,Long>> picker = builder.build();
    assert getFragmentManager() != null;
    picker.show(getFragmentManager(), picker.toString());

我想自定义对话框选择器更改文本字段,使对话框不全屏显示等.我该如何进行所有修改

i want to custom the dialog picker change text field,make dialog not full screen etc..how can i make all this modifications

推荐答案

关于全屏.

范围选择器应覆盖整个屏幕(默认值=对话框表示单个日期,全屏表示范围).但是,您可以按照自己的样式更改此行为.

The range picker should cover the entire screen (default = dialog for single date, fullscreen for range).However you can change this behavior in your style.

您可以使用 setTheme 方法来应用主题叠加层:

You can use the setTheme method to apply a theme overlay:

//To apply a dialog
builder.setTheme(R.style.ThemeOverlay_MaterialComponents_MaterialCalendar);
//To apply the fullscreen:
builder.setTheme(R.style.ThemeOverlay_MaterialComponents_MaterialCalendar_Fullscreen);

注意:它至少需要版本 1.2.0-alpha01 .

替代,您可以在应用程序主题中添加 materialCalendarFullscreenTheme 属性.

As alternative you can add in your app theme the materialCalendarFullscreenTheme attribute.

<style name="AppTheme" parent="Theme.MaterialComponents.DayNight">
   <item name="materialCalendarFullscreenTheme">@style/CustomThemeOverlay_MaterialCalendar_Fullscreen</item>
</style>

其中:

  <style name="CustomThemeOverlay_MaterialCalendar_Fullscreen"
      parent="@style/ThemeOverlay.MaterialComponents.MaterialCalendar.Fullscreen">
    <item name="materialCalendarStyle">@style/Custom_MaterialCalendar.Fullscreen</item>
  </style>

在这里您可以使用 android:windowFullscreen 属性覆盖该值:

Here you can override the value with the android:windowFullscreen attribute:

  <style name="Custom_MaterialCalendar.Fullscreen"
      parent="@style/Widget.MaterialComponents.MaterialCalendar.Fullscreen">
    <item name="android:windowFullscreen">false</item>
  </style>

关于字符串.
当前没有更改字符串的方法.
现有的唯一方法是 builder.setTitleText 来更改标题.

About the strings.
Currently there isn't a method to change the strings.
The only existing method is builder.setTitleText to change the title.

但是,您可以覆盖项目中的所有现有字符串,但是此替代方法可以停止,以便在下一发行版中运行.例如:

However you can override all the existing strings in your project, but this workaround can stop to run in the next releases.For example:

  <string name="mtrl_picker_save" description="Confirms the selection [CHAR_LIMIT=12]">....</string>
  <string name="mtrl_picker_text_input_date_range_start_hint" description="Label for the start date in a range selected by the user [CHAR_LIMIT=60]">...</string>
  <string name="mtrl_picker_text_input_date_range_end_hint" description="Label for the end date in a range selected by the user [CHAR_LIMIT=60]">...</string>

在这里您可以找到材料日历在 1.2.0-alpha02 中使用的所有字符串.

Here you can find all the strings used by the material calendar in the 1.2.0-alpha02.

这篇关于物料日期选择器自定义样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 17:23