如何使用 inputType = none 清除 AutoCompleteTextView
How to clear AutoCompleteTextView with inputType = none
我的 UI 中需要一个下拉菜单。按照我在 material.io 上找到的说明,我将 AutoCompleteTextView 与 inputType="none"
一起使用。我需要在按下按钮时重置它并再次显示占位符,但是如果我使用 setText("")
它将显示一个空的选择,我想实际上清除 AutoCompleteTextView 并再次显示占位符。我怎样才能完成它?
试试这个
在java中:
button.setOnClickListener(v->{
autoCompleteTextView.setText(null);
//autoCompleteTextView.setText("");// or you can use this
autoCompleteTextView.setFocusable(false);
});
这是 Kotlin 的:
button.setOnClickListener { v: View? ->
autoCompleteTextView.setText(null)
autoCompleteTextView.isFocusable = false
}
我的 UI 中需要一个下拉菜单。按照我在 material.io 上找到的说明,我将 AutoCompleteTextView 与 inputType="none"
一起使用。我需要在按下按钮时重置它并再次显示占位符,但是如果我使用 setText("")
它将显示一个空的选择,我想实际上清除 AutoCompleteTextView 并再次显示占位符。我怎样才能完成它?
试试这个
在java中:
button.setOnClickListener(v->{
autoCompleteTextView.setText(null);
//autoCompleteTextView.setText("");// or you can use this
autoCompleteTextView.setFocusable(false);
});
这是 Kotlin 的:
button.setOnClickListener { v: View? ->
autoCompleteTextView.setText(null)
autoCompleteTextView.isFocusable = false
}