Material 设计绘图图标不显示

Material design draw icon doesn't show

我正在尝试在刚开始使用 material 设计的文本输入字段末尾设置一个图标。 这是 XML.

**        </androidx.constraintlayout.widget.ConstraintLayout>

    <com.google.android.material.textfield.TextInputEditText
        android:id="@+id/resturantSearchPost"
        android:layout_width="0dp"
        android:layout_height="30dp"
        android:layout_marginStart="32dp"
        android:layout_marginTop="8dp"
        android:layout_marginEnd="32dp"
        android:background="@drawable/rounded_corner_rectangle"
        android:ems="10"
        android:inputType="textPersonName"
        android:textSize="24sp"
        **app:endIconDrawable="@android:drawable/ic_menu_search"**
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/constraintLayout2" />**

app:endIconDrrawable=.... 不适用于任何图标。 有什么想法吗?

需要在TextInputLayout中使用。

<com.google.android.material.textfield.TextInputLayout 
    app:endIconDrawable="@drawable/icon"> 
    ...TextInputEdittext
</com.google.android.material.textfield.TextInputLayout>

例子

 <com.google.android.material.textfield.TextInputLayout
         app:endIconDrawable="@drawable/icon"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:hint="@string/form_username">

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

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

使用 app:endIconDrawableapp:endIconMode toghader。

<com.google.android.material.textfield.TextInputLayout 
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:endIconDrawable="@drawable/ic_test"
    app:endIconMode="custom">