title: How to hide menu item from toolbar when click on search icon in android
body: <p><a href="https://i.stack.imgur.com/15sz7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/15sz7.png" alt="enter image description here"></a>My toolbar contains search icon and refresh icon,when i click on search icon then search view inflate from onCreateOptionMenu() but the refresh icon does not get hide.If i hide refresh icon in onMenuItemActionExpand() then on back press of search view back icon both menu items search and refresh gets hide and default setting icon gets visible.Below is the code which i have implemented.Please help me!!!</p>
  
  <p>MenuItem.java</p>
  
  <pre><code> @Override
          public boolean onCreateOptionsMenu(final Menu menu) {
  
              // Inflate the menu; this adds items to the action bar if it is present.
                getMenuInflater().inflate(R.menu.main, menu);
                item_search = menu.findItem(R.id.action_search);
                item_refresh = menu.findItem(R.id.action_refresh);
  
             final SearchView searchView = (SearchView) MenuItemCompat.getActionView(item_search);
              searchView.setOnSearchClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View v) {
                      // hide action item
                      if (menu != null) {
                          menu.findItem(R.id.action_refresh).setVisible(false);
                      }
  
                  }
              });
              searchView.setOnCloseListener(new SearchView.OnCloseListener() {
                  @Override
                  public boolean onClose() {
                      // re-show the action button
                      if (menu != null) {
                          menu.findItem(R.id.action_refresh).setVisible(true);
                      }
                      return false;
  
                  }
              });
  </code></pre>