0

我正在使用 android studio 3.5,这是我的 TextInputLayout 遇到的错误。布局从一开始就可以工作,但过了一段时间后,应用程序因错误而崩溃

android.view.InflateException: Binary XML file line #18: Binary XML file line #18: Error inflating class com.google.android.material.textfield.TextInputLayout
Caused by: android.view.InflateException: Binary XML file line #18: Error inflating class com.google.android.material.textfield.TextInputLayout
Caused by: java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Constructor.newInstance0(Native Method)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
    at android.view.LayoutInflater.createView(LayoutInflater.java:658)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:801)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:874)
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:835)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:877)
    at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:835)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:423)

我的布局 xml 是

<com.google.android.material.textfield.TextInputLayout
        style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        app:errorEnabled="true"
        app:hintEnabled="true"
        android:theme="@style/TextLabel">


        <com.google.android.material.textfield.TextInputEditText
            android:id="@+id/phone_number"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:ems="15"
            android:hint="@string/phone_number"
            android:inputType="number" />


    </com.google.android.material.textfield.TextInputLayout>

我的 Styles.xml 是:

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />


<style name="TextLabel" parent="Widget.MaterialComponents.TextInputLayout.FilledBox">

    <item name="colorControlActivated">@color/colorPrimary</item>
</style>

我还实现了以下依赖项,但没有帮助

implementation 'com.google.android.material:material:1.1.0-alpha06'
implementation 'com.google.android.material:material:1.0.0'

这个新的 androidx 是否也有错误,因为我在不同的布局上收到了相同的错误,这些错误在应用程序重新开始工作之前和一段时间后都可以工作?

4

1 回答 1

2

您的应用主题继承自AppCompat,但您使用的是 Material 组件。尝试将您的应用主题更改为继承自Theme.MaterialComponents.Light.NoActionBar。这应该够了吧。

于 2020-01-24T06:48:36.973 回答