Material-components-android: [MaterialDatePicker] Crash with bridge themes

Created on 3 Aug 2019  路  20Comments  路  Source: material-components/material-components-android

Description:
Crash occurs due to missing materialCalendarTheme attribute in bridge themes.

Error message:

java.lang.IllegalArgumentException: com.google.android.material.picker.MaterialDatePicker requires a value for the com.company.myapplication:attr/materialCalendarTheme 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).

Material Library version:
1.1.0-alpha09

bug

Most helpful comment

@tomblenz any fix for this issue?

The workaround above works still

<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>

All 20 comments

Thanks for reporting. We will consider moving all of our non-AppCompat/Framework attributes from our Full themes into our Bridge themes, since that should have no effect on apps being migrated from AppCompat to MaterialComponents.

For now you could set the following in your theme:

    <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>

Unfortunately, adding the materialCalender attributes to a bridge theme causes a ClassCastException to be thrown when displaying the MaterialDatePicker

java.lang.ClassCastException: androidx.appcompat.widget.AppCompatButton cannot be cast to com.google.android.material.button.MaterialButton at com.google.android.material.picker.MaterialDatePicker.onCreateView(MaterialDatePicker.java:188)

Thanks for reporting, we'll address this so MaterialDatePicker works with the Bridge themes.

This is fixed. We removed explicit references to MaterialButton in the MaterialDatePicker

Hi, I'm experiencing the same error in 1.1.0.

java.lang.IllegalArgumentException: com.google.android.material.datepicker.MaterialDatePicker requires a value for the xxxx:attr/materialCalendarTheme 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).

My theme inherits from a bridge theme

<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar.Bridge">

Hi, I'm experiencing the same error in 1.1.0.

java.lang.IllegalArgumentException: com.google.android.material.datepicker.MaterialDatePicker requires a value for the xxxx:attr/materialCalendarTheme 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).

My theme inherits from a bridge theme

<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar.Bridge">

@tomblenz any fix for this issue?

@tomblenz any fix for this issue?

The workaround above works still

<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>

@ldjcmu you should re-open this

With those lines

@tomblenz any fix for this issue?

The workaround above works still

<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>

com.google.android.material.datepicker.MaterialDatePicker requires a value for the br.com.cargafacil:attr/colorSurface 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).

colorSurface?

@vapstor any fix for the colorSurface issue ?

@vapstor
Try this:
<item name="colorSurface">#FFFFFF</item>

With those lines

@tomblenz any fix for this issue?

The workaround above works still

<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>

com.google.android.material.datepicker.MaterialDatePicker requires a value for the br.com.cargafacil:attr/colorSurface 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).

colorSurface?

Fixed this by inheriting the theme From Theme.MaterialComponents instread of ThemeOverlay

The workaround does the job. This can be closed

It is not working at all, please reopen it

Here is my codes

 <style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar.Bridge">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <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>
    <item name="colorSurface">#FFFFFF</item>
</style>

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

then

    val builder = MaterialDatePicker.Builder.dateRangePicker()
    builder.setTheme(R.style.CustomThemeOverlay_MaterialCalendar_Fullscreen)

when I remove the colorSurface field, then I get the colorSurface error thing

when I have it I get this :

android.view.InflateException: Binary XML file line #23: Binary XML file line #17: Error inflating class TextView
Caused by: android.view.InflateException: Binary XML file line #17: Error inflating class TextView
Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 5: TypedValue{t=0x2/d=0x7f0300ab a=2}
at android.content.res.TypedArray.getColorStateList(TypedArray.java:546)

at com.google.android.material.datepicker.MaterialDatePicker.onCreateView(MaterialDatePicker.java:209)

WTF going on?

I just using

implementation("com.google.android.material:material:1.3.0-alpha01")

the same with the Bridge style

When I using the built in style with the 1.3.0.alpha01

builder.setTheme(R.style.ThemeOverlay_MaterialComponents_MaterialCalendar)

Then I get the same:

java.lang.IllegalArgumentException: com.google.android.material.datepicker.MaterialDatePicker requires a value ...
attr/colorSurface 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).

It is not working at all, please reopen it

Here is my codes

 <style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar.Bridge">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <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>
    <item name="colorSurface">#FFFFFF</item>
</style>

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

then

    val builder = MaterialDatePicker.Builder.dateRangePicker()
    builder.setTheme(R.style.CustomThemeOverlay_MaterialCalendar_Fullscreen)

when I remove the colorSurface field, then I get the colorSurface error thing

when I have it I get this :

android.view.InflateException: Binary XML file line #23: Binary XML file line #17: Error inflating class TextView
Caused by: android.view.InflateException: Binary XML file line #17: Error inflating class TextView
Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 5: TypedValue{t=0x2/d=0x7f0300ab a=2}
at android.content.res.TypedArray.getColorStateList(TypedArray.java:546)

at com.google.android.material.datepicker.MaterialDatePicker.onCreateView(MaterialDatePicker.java:209)

WTF going on?

I just using

implementation("com.google.android.material:material:1.3.0-alpha01")

the same with the Bridge style

Still happening.

I just tried this with com.google.android.material:material:1.3.0-alpha01, and the date picker dialog opened fine with no crash:

<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar.Bridge">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>

    <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>

<style name="Custom_MaterialCalendar.Fullscreen" parent="@style/Widget.MaterialComponents.MaterialCalendar.Fullscreen">
    <item name="android:windowFullscreen">false</item>
</style>
MaterialDatePicker.Builder.dateRangePicker()
    .setTheme(R.style.CustomThemeOverlay_MaterialCalendar_Fullscreen)
    .build()
    .show(getSupportFragmentManager(), "TAG");

Please provide a minimal sample app that reproduces the issue.

I am getting the same crash. Here is how I defined my style:

<style name="ThemeOverlay.Catalog.MaterialCalendar.Custom" parent="@style/ThemeOverlay.MaterialComponents.MaterialCalendar"> <item name="colorPrimary">@color/myprimary_01</item> <item name="colorOnPrimary">@color/myprimary_02</item> <item name="textInputStyle">@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox</item> <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>

Please provide a minimal sample app that reproduces the issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gabrielemariotti picture gabrielemariotti  路  3Comments

Mirmuhsin picture Mirmuhsin  路  3Comments

gabrielemariotti picture gabrielemariotti  路  3Comments

JavierSegoviaCordoba picture JavierSegoviaCordoba  路  3Comments

Sanusy picture Sanusy  路  3Comments