Skip to content
Advertisement

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

I am trying to stylize the TextInputLayout with an outline. But when I try to use @style/Widget.MaterialComponents.TextInputLayout.OutlinedBox in style attribute my app crashes with this exception:

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

Here is the TextInputLayout theme I want to use OutlinedBox

It was working fine but suddenly this error appeared during development

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

</style>

Global App Theme

<!-- 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>

Advertisement

Answer

As reported in the error:

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

You have to change the app theme to a Material Components Theme like:

<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
   <!-- ... -->
</style>
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement