How to Hide Underbar in Edittext

How to hide underbar in EditText

You can set the EditText to have a custom transparent drawable or just use

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

or

android:background="@null"

or Programmatically

editText.setBackgroundResource(android.R.color.transparent);

How to remove underline below EditText indicator?

Make background like this
android:background="@null" of your editText

Remove underline from TextInputEditText

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.

How to remove the underline from the EditText field in Android?

You don't have to use any logic to remove the underlines -- just call getText().toString() when you want to use the value. It won't include special formatting or anything.



Related Topics



Leave a reply



Submit