Remove underline from TextInputEditText

后端 未结 13 2161
我寻月下人不归
我寻月下人不归 2021-01-04 01:10

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.

<         


        
相关标签:
13条回答
  • 2021-01-04 01:36
    <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>
    
    0 讨论(0)
  • 2021-01-04 01:41

    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.

    0 讨论(0)
  • 2021-01-04 01:41

    app:boxBackgroundMode="none" in parent TextInputLayout

    0 讨论(0)
  • 2021-01-04 01:42

    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.

    0 讨论(0)
  • 2021-01-04 01:42

    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>
    
    0 讨论(0)
  • 2021-01-04 01:45

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

    <item name="boxStrokeWidthFocused">0dp</item>
    <item name="boxStrokeWidth">0dp</item>
    
    0 讨论(0)
提交回复
热议问题