在自动完成文本视图中单击“完成”时,软键盘未隐藏



我的应用程序中有几个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
        }

最新更新