CURRENT SCENARIO
My app home page consists of navigation drawer, therefore I am having views loaded as fragments. I also have search icon in toolbar. I
Put this in your fragment
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
}
And you can get the SearchView like follows
@Override
public void onPrepareOptionsMenu(Menu menu) {
MenuItem mSearchMenuItem = menu.findItem(R.id.mi_search);
SearchView searchView = (SearchView) mSearchMenuItem.getActionView();
}