material-components-android icon indicating copy to clipboard operation
material-components-android copied to clipboard

[MaterialDatePicker] Lot of crash

Open klaszlo8207 opened this issue 6 years ago • 3 comments

MaterialDatePicker is crashing all the time

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

klaszlo8207 avatar Jun 30 '20 07:06 klaszlo8207

Experiencing this same issue with implementation 'com.google.android.material:material:1.3.0-SNAPSHOT'

    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=0x7f0400f2 a=6}
        at android.content.res.TypedArray.getColorStateList(TypedArray.java:538)
        at android.widget.TextView.<init>(TextView.java:1232)
        at android.widget.TextView.<init>(TextView.java:838)
        at androidx.appcompat.widget.AppCompatTextView.<init>(AppCompatTextView.java:99)
        at androidx.appcompat.widget.AppCompatTextView.<init>(AppCompatTextView.java:95)
        at androidx.appcompat.app.AppCompatViewInflater.createTextView(AppCompatViewInflater.java:182)
        at androidx.appcompat.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:103)
        at androidx.appcompat.app.AppCompatDelegateImpl.createView(AppCompatDelegateImpl.java:1407)
        at androidx.appcompat.app.AppCompatDelegateImpl.onCreateView(AppCompatDelegateImpl.java:1457)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:772)
        at android.view.LayoutInflater.parseInclude(LayoutInflater.java:965)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:859)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:866)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:866)
        at android.view.LayoutInflater.parseInclude(LayoutInflater.java:963)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:859)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
        at com.google.android.material.datepicker.MaterialDatePicker.onCreateView(MaterialDatePicker.java:209)
        at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2698)
        at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:320)
        at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1187)
        at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1356)
        at androidx.fragment.app.FragmentManager.moveFragmentToExpectedState(FragmentManager.java:1434)
        at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1497)
        at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:447)
        at androidx.fragment.app.FragmentManager.executeOps(FragmentManager.java:2169)
        at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1992)
        at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1947)
        at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1849)
        at androidx.fragment.app.FragmentManager$4.run(FragmentManager.java:413)
        at android.os.Handler.handleCallback(Handler.java:790)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6549)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:888)```

CodeIsmail avatar Jul 01 '20 13:07 CodeIsmail

I ended up created a new custom date range picker dialog. It took about 2 days.

klaszlo8207 avatar Jul 03 '20 13:07 klaszlo8207

Pickers are not supported by bridge themes. You will need a full Material theme to use date pickers.

drchen avatar Feb 18 '22 19:02 drchen