自动完成文本视图中点击“完成”后软键盘未隐藏

4
我在我的应用程序中有几个EditText,当点击“完成”键时,软键盘会隐藏。但是对于AutocompleteTextView不会发生这种情况。有什么想法吗?是否需要做更多的事情才能获得与EditText相同的行为?
<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"/>
2个回答

3
android:imeOptions="actionDone"

或者在Java代码中:

InputMethodManager in = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);    
inputManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);

出于某种原因,除了 android:imeOptions="actionDone" 之外,其他方法都对我无效... - Reuben L.
试试这行代码,老兄...它会起作用的..!! inputManager.hideSoftInputFromWindow(activity.getCurrentFocus().getApplicationWindowToken(), 0); - chakri Reddy

0
在我的情况下,setOnEditorActionListener 是个问题。所以我删除了以下代码:
searchEditText?.setOnEditorActionListener { v, actionId, event ->
            if (EditorInfo.IME_ACTION_DONE == actionId) {
                return@setOnEditorActionListener true
            } else
                return@setOnEditorActionListener false
        }

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接