Ok, I found out the following solution. I used setOnTouchListener for each view that is not an instance of searchview to collapse the search query. It worked perfect for me. Below is the code.
public void setupUI(View view) { if(!(view instanceof SearchView)) { view.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { searchMenuItem.collapseActionView(); return false; } }); }
This is the answer I spoke of.
Pankaj singhal
source share