如何解决将单击侦听器设置为 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
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。