Remove underline from TextInputEditText

后端 未结 13 2159
我寻月下人不归
我寻月下人不归 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:26

    Easy way;

    app:boxBackgroundMode="filled"
    app:boxStrokeWidth="0dp"
    
    0 讨论(0)
  • 2021-01-04 01:26

    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

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

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

    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>
    

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

    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.

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

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

    0 讨论(0)
提交回复
热议问题