当前位置:   article > 正文

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

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)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27

直接说解决办法:
修改theme 为Material的一种即可
在这里插入图片描述
在这里插入图片描述

    <!-- 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>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/235508
推荐阅读
相关标签
  

闽ICP备14008679号