Search code examples
androidonclicklistenerandroid-textinputlayoutmaterial-components-androidandroid-textinputedittext

how to click on drawableRight on every TextInputEditText


enter image description here

how to do click on drawableRight edit image of every TextInputEditText? I want to click on the edit icon and then enable to edit each field. How can i do this?

 <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <!--First name-->

            <com.google.android.material.textfield.TextInputLayout
                android:layout_width="match_parent"
                android:layout_height="@dimen/_64dp">

                <com.google.android.material.textfield.TextInputEditText
                   
                    android:id="@+id/etFirstName"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:focusableInTouchMode="true"
                    android:drawableRight="@drawable/icon_edit"
                    android:hint="@string/label_fname"
                    android:inputType="textCapWords" />
            </com.google.android.material.textfield.TextInputLayout>

            <!--Middle name-->
            <com.google.android.material.textfield.TextInputLayout
                android:id="@+id/activity_registration_tiMiddleName"
                android:layout_width="match_parent"
                android:layout_height="@dimen/_64dp">

                <com.google.android.material.textfield.TextInputEditText
                    android:id="@+id/etMiddleName"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:focusableInTouchMode="true"
                    android:drawableRight="@drawable/icon_edit"
                    android:hint="@string/label_mname"
                    android:inputType="textCapWords"/>

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


     </LinearLayout>

so how to each field individually edit using drawbleRight. Please help.


Solution

  • Don't use android:drawableRight in the TextInputEditText.
    Use:

    <com.google.android.material.textfield.TextInputLayout
        ...
        app:endIconMode="custom"
        app:endIconDrawable="@drawable/..."
    

    and:

    textInputLayout.setEndIconOnClickListener {
      // Respond to end icon presses
    }