简体   繁体   中英

How can remove underline from TextInputLayout or TextInputEditText

I want remove underline.

在 Android 上显示下划线的图片

This is my code:

<com.google.android.material.textfield.TextInputLayout
    android:id="@+id/textInputLayoutName"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="60dp"
    android:layout_marginStart="5dp"
    android:layout_marginEnd="5dp"
    app:boxCornerRadiusTopStart="20dp"
    app:boxCornerRadiusTopEnd="20dp"
    app:boxCornerRadiusBottomEnd="20dp"
    app:boxCornerRadiusBottomStart="20dp"
    >

    <com.google.android.material.textfield.TextInputEditText
        android:id="@+id/textInputEditTextName"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/register_hint_name"
        android:inputType="text"
        android:textColor="@color/black" />

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

set background like this:

android:background="@android:color/transparent"

or

android:background="@null"

you can also see this answer

just add android:background="" inside TextInputEditText

You can also create a layout file for the background you wish and set it as: android:background="@layout/nameoffile"

You can set below attributes in TextInputLayout to have no width

app:boxStrokeWidth="0dp"
app:boxStrokeWidthFocused="0dp"

Your layout

<com.google.android.material.textfield.TextInputLayout
    android:id="@+id/textInputLayoutName"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="60dp"
    android:layout_marginStart="5dp"
    android:layout_marginEnd="5dp"
    app:boxCornerRadiusTopStart="20dp"
    app:boxCornerRadiusTopEnd="20dp"
    app:boxStrokeWidth="0dp"
    app:boxStrokeWidthFocused="0dp"
    app:boxCornerRadiusBottomEnd="20dp"
    app:boxCornerRadiusBottomStart="20dp">

    <com.google.android.material.textfield.TextInputEditText
        android:id="@+id/textInputEditTextName"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/register_hint_name"
        android:inputType="text"
        android:textColor="@color/black" />

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

Preview

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM