0

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>

1 Answers1

2

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>
Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
  • 1
    Thank You so much I got it. I have to change theme of main app. – Abdul Hanan Feb 26 '20 at 12:28
  • please have a look at this issue @Gabriele https://stackoverflow.com/questions/60850751/switching-to-material-theme-from-app-compact-shows-white-blank-labels-buttons – Atif AbbAsi Mar 26 '20 at 13:08