title: How do I close a SearchView programmatically?
body: <p>I currently have a <code>SearchView</code> in the action bar of my app. When I click the search icon, the <code>SearchView</code> expands and the keyboard pops up as expected. Clicking the "X" in the <code>SearchView</code> box closes the <code>SearchView</code> as expected. However, when the <code>SearchView</code> is activated and I press the "back" button, my app is exited. This is the correct behavior, but what I am trying to do now is to capture back button press and just have it close the <code>SearchView</code> (not my app) when the <code>SearchView</code> is visible. Is there a way to invoke the <code>SearchView</code> <code>OnCloseListener()</code> programmatically on a back button press? For example, something like this:</p>
  
  <pre><code>// On a back button press, if we are currently searching,
  // close the SearchView. Otherwise, invoke normal back button
  // behavior.
  public boolean onKeyDown(int keyCode, KeyEvent event) {
     if (keyCode == KeyEvent.KEYCODE_BACK) {
          if (isSearchViewVisible) {
              SearchView searchView = (SearchView) menu.findItem(R.id.searchBox)
                 .getActionView();
  
              // This method does not exist
              searchView.invokeClose();
              return true;
          }
      }
      return super.onKeyDown(keyCode, event);
  }
  </code></pre>