从TextInputEditText中删除底部线条

32

我需要移除 TextInputEditText 的底部边框,我已将背景设置为透明和null,但是没有起作用。

<com.google.android.material.textfield.TextInputLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/bg_textinput_layout"
    android:hint="@string/app_name">

    <com.google.android.material.textfield.TextInputEditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/transparent"/>

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

bg_textinput_layout

背景文本输入布局
<?xml version="1.0" encoding="utf-8"?>

<shape xmlns:android="http://schemas.android.com/apk/res/android">

<solid android:color="@color/white"/>

<stroke android:width="@dimen/spacing_1"
    android:color="@color/hint_text_color"/>
</shape>

你不需要使用bg_textinput_layout背景。只需使用boxBackgroundColor即可拥有一个白色的框。 - Gabriele Mariotti
2
我将样式Widget.MaterialComponents.TextInputLayout.OutlinedBox应用于textinputlayout,现在它可以正常工作了。 - Balaji
1
这里有一个简单的解决方案 https://dev59.com/eVMI5IYBdhLWcg3wHHgz#63308187 - Anshad Ali KM
2个回答

69

您可以应用 app:boxStrokeWidth="0dp"app:boxStrokeWidthFocused="0dp"(或使用带有与boxBackgroundColor相同值的选择器的app:boxStrokeColor属性)。

   <com.google.android.material.textfield.TextInputLayout
       app:boxStrokeWidth="0dp"
       app:boxStrokeWidthFocused="0dp"
       ...>

enter code here

要创建一个没有背景和边框的白色框:

<com.google.android.material.textfield.TextInputLayout
    app:boxStrokeWidth="0dp"
    app:boxStrokeWidthFocused="0dp"
    app:boxStrokeColor="#FFF"
    app:boxBackgroundColor="#FFF"
    ...>

输入图片说明


2
为什么我们不能使用FilledBox隐藏底线? - ysfcyln

2

在TextInputLayout中,设置app:boxStrokeWidth="0dp";在TextInputEditText中,设置app:boxBackgroundColor="@color/white"。当背景为白色时,这对我有用。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接