Android 如何在inputType=none时清除AutoCompleteTextView
我需要一个下拉菜单在我的用户界面。按照我在上找到的说明,我将AutoCompleteTextView与Android 如何在inputType=none时清除AutoCompleteTextView,android,kotlin,material-components-android,Android,Kotlin,Material Components Android,我需要一个下拉菜单在我的用户界面。按照我在上找到的说明,我将AutoCompleteTextView与inputType=“none”一起使用。我需要在按下按钮时将其重置并再次显示占位符,但是如果我使用setText(“”),它将显示一个空选项,我希望实际清除AutoCompleteTextView并再次显示占位符。我怎样才能做到呢?试试这个 在java中: button.setOnClickListener(v->{ autoCompleteTextView.s
inputType=“none”
一起使用。我需要在按下按钮时将其重置并再次显示占位符,但是如果我使用setText(“”
),它将显示一个空选项,我希望实际清除AutoCompleteTextView并再次显示占位符。我怎样才能做到呢?试试这个
在java中:
button.setOnClickListener(v->{
autoCompleteTextView.setText(null);
//autoCompleteTextView.setText("");// or you can use this
autoCompleteTextView.setFocusable(false);
});
button.setOnClickListener { v: View? ->
autoCompleteTextView.setText(null)
autoCompleteTextView.isFocusable = false
}
这是给Kotlin的:
button.setOnClickListener(v->{
autoCompleteTextView.setText(null);
//autoCompleteTextView.setText("");// or you can use this
autoCompleteTextView.setFocusable(false);
});
button.setOnClickListener { v: View? ->
autoCompleteTextView.setText(null)
autoCompleteTextView.isFocusable = false
}
成功了,谢谢!我只是想澄清一下,我不明白为什么这里需要isFocusable=false。你能再解释一下吗?无论如何,这个解决方案是完美的!