我正在尝试在编辑文本框右侧角添加清除图标,并能够使用 Android 中的文本观察器功能清除键入的文本。
同时,我正在尝试在里面使用 Floating label edittext。但是,我无法在TextInputEditText
.
注意:我尝试过onDrawableRight
使用方法添加图像onTouchListener
,有些情况对我来说不适用。
我正在尝试在编辑文本框右侧角添加清除图标,并能够使用 Android 中的文本观察器功能清除键入的文本。
同时,我正在尝试在里面使用 Floating label edittext。但是,我无法在TextInputEditText
.
注意:我尝试过onDrawableRight
使用方法添加图像onTouchListener
,有些情况对我来说不适用。
只需将TextInputLayout
与预打包 app:endIconMode="clear_text"
属性一起使用。
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/custom_end_icon"
android:hint="Hint text"
app:endIconMode="clear_text"
...>
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
../>
</com.google.android.material.textfield.TextInputLayout>