【问题标题】:How to programmatically clear TextInputEditText in Android如何在 Android 中以编程方式清除 TextInputEditText
【发布时间】:2020-03-15 14:54:18
【问题描述】:

我不想setText("") 清除文本。 我想模拟右十字图标的点击动作。 怎么做?

【问题讨论】:

    标签: android android-textinputedittext autocompletesupportfragment


    【解决方案1】:

    基于the implementation of that icon,在TextInputEditText上调用setText(null)

    【讨论】:

      【解决方案2】:

      用途:

      if (editText != null) {
      
          editText.getText().clear();
      }
      

      【讨论】:

        【解决方案3】:

        (使用 Kotlin)

        [your ID right cross icon].setOnClickListener {
           [your ID edit text].text.clear()
        }
        

        【讨论】:

          【解决方案4】:
          (AutocompleteSupportFragment)
                          getSupportFragmentManager().findFragmentById(R.id.autocomplete_fragment).setText(null)
          

          参考:https://developers.google.com/places/android-sdk/reference/com/google/android/libraries/places/widget/AutocompleteSupportFragment#public-autocompletesupportfragment-settext-charsequence-text

          它将完全按照清除图标的作用。

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2015-04-14
            • 1970-01-01
            • 1970-01-01
            • 2014-01-14
            • 2011-07-22
            • 1970-01-01
            相关资源
            最近更新 更多