This is because SearchView is the first custom view when an action returns to view - the same problem can be seen for EditText s .
The solution is the same: set an earlier view in the hierarchy to focus. In my case, it was a Toolbar my SearchView was on top:
<android.support.v7.widget.Toolbar style="@style/ToolbarStyle" android:focusableInTouchMode="true" android:id="@+id/search_activity_toolbar" android:layout_height="?attr/actionBarSize" android:layout_width="match_parent"/> <android.support.v7.widget.SearchView android:iconifiedByDefault="false" ... />
Now I can focus on my SearchView when entering activity ( clearFocus(); requestFocus(...); ), and then when you exit the operation using the search result, then return by pressing βBackβ, the keyboard is in the same state, as with the left.
Please note that some other solutions to the related issue, namely setting windowSoftInputMode="stateUnchanged" in the Activity , did not work for me.
Adam s
source share