OK, this question has been asked many times and I have looked through many topics about it but I can not get it to work.
My searchView
is not on the actionBar so I can't use collapseActionView()
I have tried
searchView.clearFocus();//this closes the keyboard but does not remove focus
getActivity().getCurrentFocus().clearFocus(); //basically the same as above
searchView.setQuery("", false); //this clears the query and drops the keyboard
searchView.setIconified(true); // but the search retains focus and keyboard pops up again
No matter what I try I can not remove the focus from the searchView
after it has been selected
To clear focus from my searchView after executing my query I first had to add
android:focusable="true"
android:focusableInTouchMode="true"
to my parent layout of the activity. Then in the activity
LinearLayout myLayout = (LinearLayout) activity.findViewById(R.id.my_layout);
myLayout.requestFocus();
This will take the focus away from the searchView. All the info I needed was here How to remove focus without setting focus to another control?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With