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.
<
<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>
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>
.
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
.
app:boxBackgroundMode="none"
in parent TextInputLayout
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.
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>
If you want app:boxBackgroundMode with filled and without underline than this will work
<item name="boxStrokeWidthFocused">0dp</item>
<item name="boxStrokeWidth">0dp</item>