45

I have an android screen which takes email from the user. Below is the snippet of the code, I want to remove the underline which appears below the text.

<com.google.android.material.textfield.TextInputLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="8dp"
    android:hint="@string/email"
    android:textColorHint="@color/blueBackground"
    app:boxBackgroundColor="@color/input_background"
    app:boxCornerRadiusBottomEnd="20dp"
    app:boxCornerRadiusBottomStart="20dp"
    app:boxCornerRadiusTopEnd="20dp"
    app:boxCornerRadiusTopStart="20dp"
    app:endIconMode="clear_text"
    app:endIconTint="@color/blueBackground"
    app:hintTextColor="@color/blueBackground">

    <com.google.android.material.textfield.TextInputEditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textColor="@color/blueBackground"
        android:textSize="18sp"
        android:layout_margin="8dp" />

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

I have tried android:background="@null" and

<item name="colorControlNormal">@android:color/transparent</item> <item name="colorControlActivated">@android:color/transparent</item>

But it is not working.

EditText

Sagar Jogadia
  • 1,330
  • 1
  • 16
  • 25

15 Answers15

95

If you want to use the filled box then below code perfectly work for me.

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

add above lines in the input layout.

Gunavant Patel
  • 1,413
  • 1
  • 13
  • 17
25

app:boxBackgroundMode="none" in parent TextInputLayout

Pavlo28
  • 1,454
  • 2
  • 16
  • 30
24

2022 Update

My answer has been marked as the solution for the described issue, but it looks like it's got outdated and there's been a better approach around. See Gunavant Patel's answer for an up to date fix.



Original answer

It looks like the Material Components library draws its own underline using app:boxStrokeColor. This attribute is a ColorStateList, so you have to create a color state list resource in which all states' colors are set to transparent. So basically you want to create a new file res/color/filename.xml:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:color="@android:color/transparent"
        android:state_pressed="true"
        android:state_focused="true"
        android:state_selected="true"
        android:state_checkable="true"
        android:state_checked="true"
        android:state_enabled="true"
        android:state_window_focused="true" />
</selector>

and set the app:boxStrokeColor attribute to @color/filename.

However, this left me with a black underline which still doesn't respond to android:background=@null or <item name="colorControl*">@android:color/transparent</item>.


TL;DR

Quickfix: if you set the TextInputLayout outlined using style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox", the box looks almost the same, but the underline is gone. In order to remove the stroke just set the app:boxStrokeColor attribute to @null.

jsamol
  • 3,042
  • 2
  • 16
  • 27
18
<style name="Theme.MyApp" parent="Theme.MaterialComponents.Light.NoActionBar">
    <item name="textInputStyle">@style/Widget.MyApp.TextInputLayout</item>
</style>

<style name="Widget.MyApp.TextInputLayout" parent="Widget.MaterialComponents.TextInputLayout.FilledBox">
    <item name="boxStrokeWidth">0dp</item>
    <item name="boxStrokeWidthFocused">0dp</item>
</style>
fraggjkee
  • 3,524
  • 2
  • 32
  • 38
10

Please set boxBackgroundMode in TextInputLayout. This is the simple and proper way to remove underline in TextInputLayout

<com.google.android.material.textfield.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:boxBackgroundMode="none" >

        <com.google.android.material.textfield.TextInputEditText
            android:id="@+id/inputEditText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>

</com.google.android.material.textfield.TextInputLayout>
Anshad Ali KM
  • 1,207
  • 9
  • 8
9

Setting the background of the TextInputLayout to a drawable and the one of the TextInputEditText to transparent removes the underline:

<com.google.android.material.textfield.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="8dp"
        android:hint="@string/email"
        android:background="@drawable/blue_drawable"
        app:endIconMode="clear_text"
        app:endIconTint="@color/black"
        app:hintTextColor="@color/black">

    <com.google.android.material.textfield.TextInputEditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textColor="@color/black"
            android:background="@android:color/transparent"
            android:textSize="18sp"
            android:layout_margin="8dp" />

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

blue_drawable.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
<corners android:radius="20dp"/>
<solid android:color="@android:color/holo_blue_bright"/></shape>

enter image description here

no_name
  • 174
  • 1
  • 5
  • 1
    Setting `android:background="@android:color/transparent"` to `TextInputEditText` removes the blue background from the `TextInputLayout` and is therefore not solving my issue – Sagar Jogadia Jul 16 '19 at 23:54
  • I fixed this by adding a drawable as a background of the TextInputLayout – no_name Jul 17 '19 at 03:26
9

You just need write app:boxStrokeWidth="0dp" and app:boxStrokeWidthFocused="0dp" attributes for TextInputLayout component.

should be write like this:

<com.google.android.material.textfield.TextInputLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="8dp"
    app:boxStrokeWidth="0dp"
    app:boxStrokeWidthFocused="0dp"
    android:hint="@string/email"
    android:textColorHint="@color/blueBackground"
    app:boxBackgroundColor="@color/input_background"
    app:boxCornerRadiusBottomEnd="20dp"
    app:boxCornerRadiusBottomStart="20dp"
    app:boxCornerRadiusTopEnd="20dp"
    app:boxCornerRadiusTopStart="20dp"
    app:endIconMode="clear_text"
    app:endIconTint="@color/blueBackground"
    app:hintTextColor="@color/blueBackground">

<com.google.android.material.textfield.TextInputEditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textColor="@color/blueBackground"
    android:textSize="18sp"
    android:layout_margin="8dp" />

</com.google.android.material.textfield.TextInputLayout>
AlienCoder
  • 91
  • 1
  • 1
8

If you want app:boxBackgroundMode with filled and without underline than this will work

<item name="boxStrokeWidthFocused">0dp</item>
<item name="boxStrokeWidth">0dp</item>
Shweta Chauhan
  • 6,739
  • 6
  • 37
  • 57
6

Adding this line on TextInputLayout works for me:

app:boxStrokeWidth="0dp"

UPDATE

Inside color res directory add et_box_color.xml file and add below lines inside of it:

<selector xmlns:android="http://schemas.android.com/apk/res/android" >
   <item android:color="@color/transparent"
        android:state_pressed="true"
        android:state_focused="true"
        android:state_selected="true"
        android:state_checkable="true"
        android:state_checked="true"
        android:state_enabled="true"
        android:state_window_focused="true"/>
</selector>

Now add Your Material Edit text like below:

<com.google.android.material.textfield.TextInputLayout
                android:id="@+id/textInputLayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@drawable/border"
                app:boxStrokeColor="@color/et_box_color"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/llBank">

                <com.google.android.material.textfield.TextInputEditText
                    android:id="@+id/etAmount"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="1dp"
                    android:background="#00FFFFFF"
                    android:gravity="center"
                    android:hint="Amount"
                    android:imeOptions="actionDone"
                    android:inputType="numberDecimal" />

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

I added a background to make a border of the TextInputLayout, remove background of TextInputLayout if you don't need. Background of TextInputEditText will be necessary to make background transparent.

Touhid
  • 1,556
  • 18
  • 18
6

The solution is very simple, you have to add this line to TextInputLayout : style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox" and it will be fixed.

topsoftwarepro
  • 773
  • 5
  • 19
3

Easy way;

app:boxBackgroundMode="filled"
app:boxStrokeWidth="0dp"
Cafer Mert Ceyhan
  • 1,640
  • 1
  • 13
  • 17
1

Create a selector at res/drawable

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:alpha="0.01" android:color="?attr/background" android:state_focused="true"/>
    <item android:alpha="0.01" android:color="?attr/background" android:state_hovered="true"/>
    <item android:alpha="0.01" android:color="?attr/background" android:state_enabled="false"/>
    <item android:alpha="0.01" android:color="?attr/background"/>
</selector>

background here - any color that is close to you background.

Way 1 Then set it to your TextInputLayout:

<com.google.android.material.textfield.TextInputLayout
...
  app:boxStrokeColor="@drawable/text_input_selector"
...

Way 2, trough styles:

styles.xml:

<style name="vm_textFilledBox" parent="Widget.MaterialComponents.TextInputLayout.FilledBox">
        <item name="boxStrokeColor">@drawable/text_input_selector</item>
</style>
 <com.google.android.material.textfield.TextInputLayout
...
    style="@style/vm_textFilledBox"
Evgenii Vorobei
  • 1,457
  • 18
  • 20
0

Make your custom TextInputLayout like this

package com.google.android.material.textfield

import android.content.Context
import android.util.AttributeSet
class TextInputLayoutWithoutUnderline @JvmOverloads constructor(
        context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : TextInputLayout(context, attrs, defStyleAttr) {

    override fun updateEditTextBackground() {
        // XXX don't call super on purpose
    }

}
logcat
  • 3,435
  • 1
  • 29
  • 44
0

Note: This answer about removing the underline while typing in TextInputEditText

After searching 6 hours about how to remove the underline from TextInputEditText, I found a single line solution, its just put android:inputType="text|textNoSuggestions" inside your TextInputEditText.

Now i am not getting any underline while typing in TextInputEditText

iamkdblue
  • 3,448
  • 2
  • 25
  • 43
-1

Try setting background to @null or @android:color/transparent

Tamir Abutbul
  • 7,301
  • 7
  • 25
  • 53
SABANTO
  • 1,316
  • 9
  • 24