【问题标题】:Does Android EditText has input type with clear button?Android EditText 是否具有带清除按钮的输入类型?
【发布时间】:2011-11-16 04:39:04
【问题描述】:

Android EditText 是否有带清除按钮的输入类型?

它应该像 html 5 搜索输入类型一样工作。

【问题讨论】:

标签: android


【解决方案1】:

没有内部输入类型,但您可以对其进行自定义以使其正常工作。此链接可能对您有所帮助:Stack-Overflow: EditText with clear button

【讨论】:

  • 伤心,希望安卓能帮我处理
  • 别难过,在 TextInputLayout 中使用 app:endIconMode="clear_text"。
  • @MahdiMoqadasi android.support.design.widget.TextInputLayout有这个功能吗,如果没有请指定使用哪个TextInputLayout??
  • 请参阅下面的@sergio-sánchez-sánchez 答案。 stackoverflow.com/a/64786871/5853262
【解决方案2】:

如果您使用的是TextInputLayout,则可以使用endIconModeendIconDrawable

【讨论】:

  • android.support.design.widget.TextInputLayout有这个功能吗,如果没有请指定使用哪个TextInputLayout??
  • @KJEjava48 使用com.google.android.material.textfield.TextInputLayout。您可以从.xml 设置图标。比如app:endIconDrawable="@drawable/xxx
  • 我有一个日期选择器编辑文本字段,其中 android:focusable="false" ,我如何将其用于此类字段???请帮助
【解决方案3】:

你可以使用下面的,效果很好

<?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 无效

【讨论】:

    猜你喜欢
    • 2011-08-10
    • 2014-05-28
    • 2021-08-02
    • 1970-01-01
    • 2019-04-09
    • 1970-01-01
    • 1970-01-01
    • 2015-03-22
    • 1970-01-01
    相关资源
    最近更新 更多