gpt4 book ai didi

android - MaterialDatePicker 错误 : materialCalendarFullscreenTheme attribute to be set in your app theme

转载 作者:行者123 更新时间:2023-12-03 13:45:41 31 4
gpt4 key购买 nike

我做了什么:

  • 已添加 implementation 'com.google.android.material:material:1.1.0'在依赖项中
  • 设置 Theme.MaterialComponents.Light.Bridge作为应用主题的父级
  •      <style name="AppTheme" parent="Theme.MaterialComponents.Light.Bridge">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    </style>
  • 试图在 fragment 中显示日期选择器。
  • MaterialDatePicker.Builder<Pair<Long, Long>> builder = MaterialDatePicker.Builder.dateRangePicker();

    Calendar now = Calendar.getInstance();
    now.set(Calendar.YEAR, 2020);
    now.set(Calendar.MONTH, 1);
    now.set(Calendar.DAY_OF_MONTH, 10);

    long first = now.getTimeInMillis();

    now.set(Calendar.YEAR, 2020);
    now.set(Calendar.MONTH, 5);
    now.set(Calendar.DAY_OF_MONTH, 20);

    long last = now.getTimeInMillis();

    builder.setSelection(new Pair<>(first, last));

    MaterialDatePicker<Pair<Long, Long>> picker = builder.build();

    picker.show(fragmentActivity.getSupportFragmentManager(), "RangePicker");

    当我运行代码时,得到了这个错误
    java.lang.IllegalArgumentException: com.google.android.material.datepicker.MaterialDatePicker
    requires a value for the com.example:attr/materialCalendarFullscreenTheme attribute to be set
    in your app theme. You can either set the attribute in your theme or update your theme to
    inherit from Theme.MaterialComponents (or a descendant).

    最佳答案

    只需将以下内容添加到您的应用主题中。

    <item name="materialCalendarStyle">@style/Widget.MaterialComponents.MaterialCalendar</item>
    <item name="materialCalendarFullscreenTheme">@style/ThemeOverlay.MaterialComponents.MaterialCalendar.Fullscreen</item>
    <item name="materialCalendarTheme">@style/ThemeOverlay.MaterialComponents.MaterialCalendar</item>

    添加后
    <style name="AppTheme" parent="Theme.MaterialComponents.Light.Bridge">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>

    <!-- Add these -->
    <item name="materialCalendarStyle">@style/Widget.MaterialComponents.MaterialCalendar</item>
    <item name="materialCalendarFullscreenTheme">@style/ThemeOverlay.MaterialComponents.MaterialCalendar.Fullscreen</item>
    <item name="materialCalendarTheme">@style/ThemeOverlay.MaterialComponents.MaterialCalendar</item>
    </style>

    关于android - MaterialDatePicker 错误 : materialCalendarFullscreenTheme attribute to be set in your app theme,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60870677/

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