Remove underline from TextInputEditText
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.
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
.
<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>