Como ocultar a pesquisa no menu Android Studio da atividade

// put below code in oncreatOptionMenu(); 
// the use  flag as global variable in your class 
// change its value as you need the call the function invalidateOptionsMenu()
// this function is call the oncreateOptionMenu()
MenuItem item = menu.findItem(R.id.menu_Done);

if (flag/condition)) {
  item.setVisible(false); // its a simple example
} else { 
   item.setVisible(true); 
}
Mohamed Boumlyk