android Error inflating class com.google.android.material.chip.Chip

盖锦程
2023-12-01

异常:

E/AndroidRuntime: FATAL EXCEPTION: main
   android.view.InflateException: Binary XML file line #34 in .....: Binary XML file line #34 in .....: Error inflating class com.google.android.material.chip.Chip
        at ..: Binary XML file line #34 in 


: Error inflating class com.google.android.material.chip.Chip
     Caused by: android.view.InflateException: Binary XML file line #34 in .......: Error inflating class com.google.android.material.chip.Chip
     Caused by: java.lang.reflect.InvocationTargetException

com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1101)
     Caused by: java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant).
        at com.google.android.material.internal.ThemeEnforcement.checkTheme(ThemeEnforcement.java:248)
        at com.google.android.material.internal.ThemeEnforcement.checkMaterialTheme(ThemeEnforcement.java:222)
        at com.google.android.material.internal.ThemeEnforcement.checkCompatibleTheme(ThemeEnforcement.java:150)
        at com.google.android.material.internal.ThemeEnforcement.obtainStyledAttributes(ThemeEnforcement.java:81)
        at com.google.android.material.chip.ChipDrawable.loadFromAttributes(ChipDrawable.java:334)
        at com.google.android.material.chip.ChipDrawable.createFromAttributes(ChipDrawable.java:276)
        at com.google.android.material.chip.Chip.<init>(Chip.java:193)
        at com.google.android.material.chip.Chip.<init>(Chip.java:186)
        	... 30 more

解决办法:

在vale->styles.xml文件中修改 <style name="AppTheme" parent="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>

 

 

 

 

 

 

 类似资料:

相关阅读

相关文章

相关问答