【问题标题】:Android material design textinputlayoutAndroid材料设计文本输入布局
【发布时间】:2021-05-17 07:44:55
【问题描述】:

有没有办法处理android材料输入中的后缀onclick事件? 我有这样的 xml 布局

 <?xml version="1.0" encoding="utf-8"?>
    <layout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            xmlns:tools="http://schemas.android.com/tools">
    
        <data>
    
        </data>
    
        <androidx.constraintlayout.widget.ConstraintLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                tools:context=".MainActivity">
    
            <com.google.android.material.textfield.TextInputLayout
                    android:id="@+id/inputLayout"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="24dp"
                    android:layout_marginTop="24dp"
                    android:layout_marginEnd="24dp"
                    app:endIconDrawable="@drawable/change_icon"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent"
                    app:suffixText="verify">
    
                <com.google.android.material.textfield.TextInputEditText
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:hint="email" />
            </com.google.android.material.textfield.TextInputLayout>
        </androidx.constraintlayout.widget.ConstraintLayout>
    </layout>

我想发送到服务器请求,当用户点击验证文本时,我如何释放这个案例?

【问题讨论】:

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


    【解决方案1】:

    你可以使用:

        inputLayout.suffixTextView.setOnClickListener {
            //do something..
        }
    

    【讨论】:

      【解决方案2】:

      这可能有助于您尝试处理按下结束图标。

      textField.setEndIconOnClickListener {
        // Respond to end icon presses}
      
      textField.addOnEditTextAttachedListener {
        // If any specific changes should be done when the     edit text is attached (and
        // thus when the trailing icon is added to it), set  an
        // OnEditTextAttachedListener.
      
        // Example: The clear text icon's visibility behavior depends on whether the
        // EditText has input present. Therefore, an OnEditTextAttachedListener is set
        // so things like editText.getText() can be called.
      }
      
      textField.addOnEndIconChangedListener {
        // If any specific changes should be done if/when the endIconMode gets
        // changed, set an OnEndIconChangedListener.
      
        // Example: If the password toggle icon is set and a different EndIconMode
        // gets set, the TextInputLayout has to make sure that the edit text's
        // TransformationMethod is still PasswordTransformationMethod. Because of
        // that, an OnEndIconChangedListener is used.
      }
      

      如果您需要官方文档的链接here you go

      【讨论】:

      • You question needs more explanation. 如果你有这样的感觉,你应该在尝试回答之前发表评论,我个人觉得这个问题很有道理
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-24
      • 1970-01-01
      • 2019-11-25
      • 1970-01-01
      • 1970-01-01
      • 2017-01-27
      相关资源
      最近更新 更多