android - 设置点击监听器到 TextInputEditText drawable Right/End android studio
问题描述
我有一个文本输入布局,里面有文本输入编辑文本。文本输入编辑文本最后有一个 Drawable。我想要实现的是让drawable在最后被点击时做一些事情,例如显示一个Toast消息
下面是我的 XML 代码
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/til_toast"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="5dp"
android:layout_marginRight="5dp"
android:layout_marginBottom="5dp"
android:padding="3dp">
<!--android:maxLength="13"-->
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/et_toast"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableEnd="@drawable/ic_calendar"
android:drawableRight="@drawable/ic_calendar"
android:hint="@string/date_from"
android:inputType="date" />
</com.google.android.material.textfield.TextInputLayout>
我怎样才能做到这一点
解决方案
不要在. android:drawableRight
_android:drawableEnd
TextInputEditText
相反,您可以使用:
<com.google.android.material.textfield.TextInputLayout
...
app:endIconMode="custom"
app:endIconDrawable="@drawable/..."
然后使用endIconOnClickListener
:
textInputLayout.setEndIconOnClickListener {
// Respond to end icon presses
}
推荐阅读
- devise - 你如何让 Devise 向 Facebook 发送语言环境参数
- angular - 在 Angular 中使用 ngModel 指令获取表单中的所有值
- java - 如何将 char 数组拆分成块,这是一个新数组(Java 8)
- c# - C#.net Web 请求在调用 Web API 时无法获得 404 自定义错误消息,但邮递员可以
- string - 提取所有无空间字符串
- php - 如何从xml中的字符串解析url
- python - NER - 实体识别 - 国家过滤器
- symfony - Symfony 4:删除所有以某事开头的缓存项
- mysql - MYSQL 在子查询中分组但需要所有数据
- javascript - 使用 pureJS 进行拖放且无后端