本文介绍了IllegalArgumentException尝试使用@ style/Widget.MaterialComponents.TextInputLayout.OutlinedBox时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试对 TextInputLayout 的轮廓进行样式化.但是,当我尝试在样式属性中使用@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).

这是我要使用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>

推荐答案

错误报告:

您必须将应用程序主题更改为Material Components Theme,例如:

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

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

这篇关于IllegalArgumentException尝试使用@ style/Widget.MaterialComponents.TextInputLayout.OutlinedBox时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 07:54