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

浪子不回头ぞ 提交于 2020-06-23 16:00:26

问题


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:


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>


来源:https://stackoverflow.com/questions/60269400/illegalargumentexception-when-trying-to-use-style-widget-materialcomponents-tex

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!