IllegalArgumentException 尝试使用 @style/Widget.MaterialComponents.TextInputLayout.OutlinedBox 时

IllegalArgumentException When trying to use @style/Widget.MaterialComponents.TextInputLayout.OutlinedBox

我正在尝试 风格化 TextInputLayout 的轮廓。但是当我尝试在样式属性中使用 @style/Widget.MaterialComponents.TextInputLayout.OutlinedBox 时,我的应用程序崩溃并出现以下异常:

Caused by: java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant).

这是我要使用 OutlinedBox 的 TextInputLayout 主题

本来好好的,开发的时候突然出现这个错误

<style name="LoginTextInputLayoutStyle" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense">
    <item name="boxStrokeColor">@color/text_input_box_stroke</item>

</style>

全球应用主题

<!-- Base application No Action bar theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:fontFamily">@font/opensans_regular</item>
    </style>

如报错:

Caused by: java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant)

您必须 change the app theme 到 Material 组件主题,例如:

<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
   <!-- ... -->
</style>