Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android searchView not in actionBar remove focus

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

like image 206
Gooner Avatar asked Sep 14 '15 11:09

Gooner


1 Answers

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?

like image 197
Gooner Avatar answered Oct 06 '22 01:10

Gooner