Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Floating Label TextInputLayout insideTextInputEdittext add clear icon right side corner with onclick functionality

I am trying to add clear icon in edit text box right side corner and able to clear the typed text using text watcher functionality in Android.

At the same I am trying in for Floating label edittext inside. But, I could not able to add the clear icon/button on right side corner of TextInputEditText.

Note: I have tried onDrawableRight image adding with onTouchListener method, some of the situation not work out for me.

like image 809
harikrishnan Avatar asked Sep 05 '25 03:09

harikrishnan


1 Answers

Just use the TextInputLayout with the pre-packaged app:endIconMode="clear_text" attribute.

   <com.google.android.material.textfield.TextInputLayout
        android:id="@+id/custom_end_icon"
        android:hint="Hint text"
        app:endIconMode="clear_text"
        ...>

        <com.google.android.material.textfield.TextInputEditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            ../>

    </com.google.android.material.textfield.TextInputLayout>

enter image description here

like image 174
Gabriele Mariotti Avatar answered Sep 07 '25 20:09

Gabriele Mariotti