如何在每个 TextInputEditText 上单击 drawableRight

how to click on drawableRight on every TextInputEditText

点击每个TextInputEditText的drawableRight编辑图片怎么办?我想单击编辑图标,然后启用编辑每个字段。我该怎么做?

 <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>

那么如何使用 drawbleRight 单独编辑每个字段。请帮忙

不要在 TextInputEditText 中使用 android:drawableRight
使用:

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

和:

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

您可以为此覆盖 onTouch 函数。

 @Override
public boolean onTouch(View view, MotionEvent event) {
    final int DRAWABLE_LEFT = 0;
    final int DRAWABLE_TOP = 1;
    final int DRAWABLE_RIGHT = 2;
    final int DRAWABLE_BOTTOM = 3;

    if(event.getAction() == MotionEvent.ACTION_UP) {
        if(event.getRawX() >= (etFirstName.getRight() - etFirstName.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width())) {
            // your action here
            
      }
    return false;
}