7

我正在尝试将一个结束 Icon Drawable 添加到我的文本输入布局中。我遇到了这样做的方法,但是当我尝试实现它时,它不起作用。

Material io 说显示尾随图标所需要做的就是添加app:endIconDrawable="@drawable/your_icon_here"当我这样做时,我没有得到要显示的图标。我正在使用的图标是从 Google 的材质图标库作为 SVG 下载的,我将它作为矢量资源导入到项目中。

下面是我的代码和我得到的结果图片。(我已经打破了界限,以便更容易找到图标的调用)

<com.google.android.material.textfield.TextInputLayout
  android:id="@+id/input_layout_event_name"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:layout_marginTop="8dp"
  android:hint="@string/ec_event_name"

  app:endIconDrawable="@drawable/ic_event_black_24dp"

  app:errorEnabled="false"
  app:boxBackgroundColor="@android:color/transparent"
  android:background="@android:color/transparent">

     <com.google.android.material.textfield.TextInputEditText
       android:id="@+id/input_event_name"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:inputType="textAutoCorrect" />

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

上述代码的模拟器结果

任何帮助表示赞赏!

4

4 回答 4

20

结束图标不可见,因为它默认处于禁用状态 (END_ICON_NONE)。将此属性添加到TextInputLayout

app:endIconMode="custom"
于 2021-08-15T11:39:11.710 回答
2

android:drawableEnd在你的TextInputEditText

android:drawableEnd="@drawable/your_icon_here"
于 2021-07-15T15:57:46.630 回答
1

您需要使用这种方式:

<com.google.android.material.textfield.TextInputLayout 
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:endIconDrawable="@drawable/ic_calendar"
    app:endIconMode="custom">
于 2021-08-28T14:42:36.597 回答
0

你错过了属性app:passwordToggleEnabled="true"app:endIconMode="password_toggle"TextInputLayout

于 2021-08-19T07:55:00.647 回答