Error inflating class com.google.android.material.button.MaterialButton

在xml里面使用MaterialButton的时候报错,报错信息如下:

 Caused by: android.view.InflateException: Binary XML file line #141: Binary XML file line #141: Error inflating class com.google.android.material.button.MaterialButton
        at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
        at androidx.databinding.DataBindingUtil.inflate(DataBindingUtil.java:126)
        at androidx.databinding.ViewDataBinding.inflateInternal(ViewDataBinding.java:1368)
        at com.ly.largescreencalendar.databinding.FragmentCalendarBinding.inflate(FragmentCalendarBinding.java:108)
        at com.ly.largescreencalendar.databinding.FragmentCalendarBinding.inflate(FragmentCalendarBinding.java:94)
        at com.ly.largescreencalendar.CalendarDialogFragment.onCreateView(CalendarDialogFragment.kt:73)
        at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2698)
        at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:310)
        at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1185)
        at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1354)
        at androidx.fragment.app.FragmentManager.moveFragmentToExpectedState(FragmentManager.java:1432)
        at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1495)
        at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:447)
        at androidx.fragment.app.FragmentManager.executeOps(FragmentManager.java:2167)
        at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1990)
        at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1945)
        at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1847)
        at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:2621)
        at androidx.fragment.app.FragmentManager.dispatchActivityCreated(FragmentManager.java:2569)
        at androidx.fragment.app.FragmentController.dispatchActivityCreated(FragmentController.java:247)
        at androidx.fragment.app.FragmentActivity.onStart(FragmentActivity.java:541)
        at androidx.appcompat.app.AppCompatActivity.onStart(AppCompatActivity.java:201)
        at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1237)
        at android.app.Activity.performStart(Activity.java:6283)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379)

直接说解决办法:
修改theme 为Material的一种即可
Error inflating class com.google.android.material.button.MaterialButton_第1张图片
Error inflating class com.google.android.material.button.MaterialButton_第2张图片

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.MaterialComponents.DayNight">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

打完收工,下一章讲一下为什么要用MaterialButton,能给我们带来什么

你可能感兴趣的:(Android基础)