我的应用程序中有多个EditText
,并且单击“完成”键时,软键盘被隐藏。 AutocompleteTextView
不会发生这种情况。
知道为什么吗?要使用AutocompleteTextView
获得相同的行为,还有其他事情要做吗?
<AutoCompleteTextView
android:id="@+id/autoCompleteTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_below="@id/search_zip"
android:layout_toLeftOf="@id/submit"
android:paddingLeft="10dp"
android:hint="@string/city_or_zip"
android:background="@drawable/bt_grey"
android:inputType="text"/>
android:imeOptions="actionDone"
或使用Java代码:
InputMethodManager in = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
就我而言,setOnEditorActionListener
出了问题。所以我删除了下面的代码:
searchEditText?.setOnEditorActionListener { v, actionId, event ->
if (EditorInfo.IME_ACTION_DONE == actionId) {
return@setOnEditorActionListener true
} else
return@setOnEditorActionListener false
}