出现The style on this component requires your app theme to be Theme.MaterialComponents错误

我碰到这样的问题是由于我是用MaterialCardView时出现的,可能使用使用其他的Material库的控件时,也会出现这样的错误提示。这个错误就是说当前组件的主题是需要 Theme.MaterialComponents这样的主题。那么如何修改呢???

只需要在style.xml文件中,修改一下主题就可以了。

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

只需要换前面的就可以了,后面具体想要什么样的还是和之前一样的。

如果大家还有更好的解决办法,可以在评论留言交流哦!!!

你可能感兴趣的:(踩坑记录,android)