Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EndIcon is default displayed when set text in TextInputLayout

I want to know how to hide by default

When the screen is rotated or setText () is displayed in the same way

<com.google.android.material.textfield.TextInputLayout
    android:id="@+id/addressTextInputLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:endIconMode="clear_text"
    app:hintEnabled="false"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/label2">

    <EditText
        android:layout_width="match_parent"
        android:layout_height="44dp"
        android:hint=""
        android:text="test"
        android:inputType="text"
        android:padding="10dp" />

</com.google.android.material.textfield.TextInputLayout>
like image 214
Kazunari Sugimoto Avatar asked Mar 13 '26 22:03

Kazunari Sugimoto


1 Answers

You can create an extension function of TextInputEditText to set the text and disable the endIcon for the parent layout.

fun TextInputEditText.setTextWithoutEndIcon(content: String, parentLayout: TextInputLayout){
this.setText(content)
parentLayout.isEndIconVisible = false
}

So just pass the textInputLayout of that edittext and it will disable the endIcon. Be careful to not pass other edittext's textInputLayout.

Also, I would suggest to make a customTextInputEditText and put this function in there which would give you better flexibility and you would be able to define your purposes in a better way. This way, you can have the material TextInputEditText with it's default properties (unmodified) and your own textinputEditText (modified).

Cheers!

like image 107
Rishabh Kamdar Avatar answered Mar 16 '26 00:03

Rishabh Kamdar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!