首页 > 解决方案 > 如何从 TextInputLayout 中删除白框

问题描述

今天我刚刚更新了我dependenciesmaterial design

1.0.01.1.0-alpha09

implementation 'com.google.android.material:material:1.1.0-alpha09'

现在我遇到了奇怪的问题com.google.android.material.textfield.TextInputLayout

这是我的代码

            <com.google.android.material.textfield.TextInputLayout
                android:id="@+id/emailTextInputLayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="@dimen/_10sdp">

            <com.google.android.material.textfield.TextInputEditText
                    android:id="@+id/emailTextInputEditText"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="@string/hint_enter_email"
                    android:imeOptions="actionNext"
                    android:inputType="textEmailAddress"/>
        </com.google.android.material.textfield.TextInputLayout>

更新依赖项后,我得到了盒装设计TextInputLayout

上述代码的输出

在此处输入图像描述

如果我使用implementation 'com.google.android.material:material:1.0.0'我会得到预期的结果

在此处输入图像描述

谁能帮我解决这个问题

如果需要更多信息,请告诉我。提前致谢。您的努力将不胜感激。

更新

我已经试过 app:boxBackgroundMode="none"了,我得到了这个

输出,

如果我使用app:boxBackgroundMode="outline"然后得到这个

输出

解决了

无需使用boxBackgroundMode

您需要@style/Widget.Design.TextInputLayout在您的TextInputLayout

示例代码

        <com.google.android.material.textfield.TextInputLayout
                android:id="@+id/emailTextInputLayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="@dimen/_10sdp"
                style="@style/Widget.Design.TextInputLayout"
                app:errorTextAppearance="@style/error_appearance"
                android:textColorHint="@android:color/white">

            <com.google.android.material.textfield.TextInputEditText
                    android:layout_width="match_parent"
                    android:id="@+id/emailTextInputEditText"
                    android:layout_height="wrap_content"
                    android:backgroundTint="@android:color/white"
                    android:gravity="center"
                    android:hint="@string/hint_enter_email"
                    android:imeOptions="actionNext"
                    android:textColorHint="@android:color/white"
                    android:inputType="textEmailAddress"
                    android:textColor="@android:color/white"
                    android:textSize="@dimen/_15ssp"/>
        </com.google.android.material.textfield.TextInputLayout>

输出 在此处输入图像描述

标签: androidandroid-layoutmaterial-designandroidxandroid-textinputlayout

解决方案


要恢复到没有归档背景但只有底部边框的旧样式,应该使用以下样式:

<com.google.android.material.textfield.TextInputLayout
           ...
           style="@style/Widget.Design.TextInputLayout"
           ....
           >
</com.google.android.material.textfield.TextInputLayout>

使用主题Widget.Design.TextInputLayout将生成预期的输出,如下所示:

在此处输入图像描述


推荐阅读