【问题标题】:Floating Label TextInputLayout insideTextInputEdittext add clear icon right side corner with onclick functionality浮动标签 TextInputLayout insideTextInputEdittext 添加清除图标右侧角与 onclick 功能
【发布时间】:2019-01-18 12:30:34
【问题描述】:

我正在尝试在编辑文本框右侧角添加清除图标,并能够使用 Android 中的文本观察器功能清除键入的文本。

同时我正在尝试使用浮动标签编辑文本。但是,我无法在TextInputEditText 的右侧角添加清除图标/按钮。

注意:我已经尝试使用onTouchListener 方法添加onDrawableRight 图像,但有些情况不适用于我。

【问题讨论】:

    标签: android material-design android-textinputlayout material-components material-components-android


    【解决方案1】:

    只需使用 TextInputLayout 和 pre-packaged 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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-11
      • 2016-10-24
      • 1970-01-01
      • 2012-10-04
      • 2022-11-30
      相关资源
      最近更新 更多