在AutocompleteTextView中单击完成后,软键盘不会隐藏

问题描述 投票:2回答:2

我的应用程序中有多个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 autocompletetextview
2个回答
2
投票
android:imeOptions="actionDone"

或使用Java代码:

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

0
投票

就我而言,setOnEditorActionListener出了问题。所以我删除了下面的代码:

searchEditText?.setOnEditorActionListener { v, actionId, event ->
            if (EditorInfo.IME_ACTION_DONE == actionId) {
                return@setOnEditorActionListener true
            } else
                return@setOnEditorActionListener false
        }
© www.soinside.com 2019 - 2024. All rights reserved.