无法在Fragment中使用TextInputLayout

时间:2018-05-22 19:23:23

标签: android android-fragments android-textinputlayout

我似乎无法在片段中使用TextInputLayout。这是我的代码。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:gravity="center_horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".LoginFragment">

    <android.support.design.widget.TextInputLayout
        android:id="@+id/email_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.design.widget.TextInputEditText
            android:id="@+id/email"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="email"
            android:inputType="textEmailAddress"
            android:maxLines="1" />

    </android.support.design.widget.TextInputLayout>

</LinearLayout>

当我尝试跑步时,我得到了这个例外

Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.design.widget.TextInputLayout"

我红了这个post,说我应该使用AppCompat Theme而我正在使用AppCompat Theme

这是我的主题

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

1 个答案:

答案 0 :(得分:1)

将此依赖项添加到gradle解决了问题

implementation 'com.android.support:design:27.1.1'