Android 使用 'app:errorEnabled="true"' 到 TextInputLayout 时出现错误

Android getting error when use 'app:errorEnabled="true"' to TextInputLayout

在我的应用程序中,我在布局 TextInputLayout 中。当我写 app:errorEnabled="true" 行时,我收到此错误

Unhandled Exception: Android.Views.InflateException: Binary XML file line #1: Binary XML file line #1: Error inflating class android.support.design.widget.TextInputLayout

添加此行之前一切正常

这是我的 TextInputLayout 的代码

<android.support.design.widget.TextInputLayout
    android:id="@+id/til_email"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="130"
    android:layout_marginLeft="25dp"
    android:layout_marginRight="25dp"
    android:theme="@style/TextLabel"
    app:errorTextAppearance="@style/MyErrorText"
    app:errorEnabled="true">
  <EditText
      android:id="@+id/input_email"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:singleLine="true"
      android:inputType="textEmailAddress"
      android:drawableStart="@mipmap/stroke"
      android:drawableLeft="@mipmap/stroke"
      android:theme="@style/TextLabel"
      android:backgroundTint="#9fa7b3"
      android:hint="@string/username" />
</android.support.design.widget.TextInputLayout>

这是我的样式文件代码

<!---Style for LoginPage edit texts-->
<style name="TextLabel" parent="TextAppearance.AppCompat">
<!-- Hint color and label color in FALSE state -->
<item name="android:textColorHint">#353535</item>
<item name="android:textSize">20sp</item>
<!-- Label color in TRUE state and bar color FALSE and TRUE State -->
<item name="colorAccent">#353535</item>
<item name="colorControlNormal">#353535</item>
<item name="colorControlActivated">#55b9aa</item>
<item name="colorControlHighlight">#353535</item>
</style>

<!--Error label text style-->
<style name="MyErrorText" parent="TextAppearance.AppCompat.Small">
<item name="android:textColor">@color/Pink</item>
</style>

我也在用

public class LoginActivity : AppCompatActivity

app:errorEnabled="true"没有问题 从 <android.support.design.widget.TextInputLayout 中删除 theme 属性,因为您也在 EditText

中设置它

完整代码如下:

<android.support.design.widget.TextInputLayout
android:id="@+id/til_email"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="130"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
app:errorTextAppearance="@style/MyErrorText"
app:errorEnabled="true">
<EditText
  android:id="@+id/input_email"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:singleLine="true"
  android:inputType="textEmailAddress"
  android:drawableStart="@mipmap/stroke"
  android:drawableLeft="@mipmap/stroke"
  android:theme="@style/TextLabel"
  android:backgroundTint="#9fa7b3"
  android:hint="@string/username" />
</android.support.design.widget.TextInputLayout>