【发布时间】:2011-11-16 04:39:04
【问题描述】:
Android EditText 是否有带清除按钮的输入类型?
它应该像 html 5 搜索输入类型一样工作。
【问题讨论】:
标签: android
Android EditText 是否有带清除按钮的输入类型?
它应该像 html 5 搜索输入类型一样工作。
【问题讨论】:
标签: android
没有内部输入类型,但您可以对其进行自定义以使其正常工作。此链接可能对您有所帮助:Stack-Overflow: EditText with clear button
【讨论】:
如果您使用的是TextInputLayout,则可以使用endIconMode 和endIconDrawable
【讨论】:
com.google.android.material.textfield.TextInputLayout。您可以从.xml 设置图标。比如app:endIconDrawable="@drawable/xxx。
你可以使用下面的,效果很好
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.textfield.TextInputLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/textInputLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:endIconMode="clear_text"
tools:hint="Label">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/textInputEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:text="Value" />
</com.google.android.material.textfield.TextInputLayout>
但这种方法对 MaterialAutoCompleteTextView 无效
【讨论】: