title: MenuItemCompat.setOnActionExpandListener doesn't do anything
body: <h2>Background</h2>
  
  <p>I have a searchView being initialized using a special class I've made, that's being used across all of the activities and fragments.</p>
  
  <h2>The problem</h2>
  
  <p>Recently, probably due to updates to the support library (or because I didn't use it so far, I don't remember), I can't catch events of expand/collapse of the searchView.</p>
  
  <p>As I've found, this happens even if I use setSupportActionBar with a Toolbar instance.</p>
  
  <h2>What I've tried</h2>
  
  <p>I've tried using each of the next methods, but none worked:</p>
  
  <ul>
  <li>MenuItemCompat.setOnActionExpandListener.</li>
  <li>MenuItemCompat.setOnActionExpandListener together with iconifying the SearchView, as suggested on some websites.</li>
  <li>setOnActionExpandListener on the search menu item itself, but then it crashes since it can't be used when extending the ActionBarActivity.</li>
  <li>SearchView.setOnCloseListener , but this works only if I close it, and only using the UI (doesn't get called when calling collapseActionView ).</li>
  <li>I've also tried to mess around with the XML file of the search menu item. </li>
  </ul>
  
  <h2>The code</h2>
  
  <p>Here's the helper class I've made:</p>
  
  <p><strong>SearchHolderCompat</strong> </p>
  
  <pre><code>public class SearchHolderCompat {
      public MenuItem mSearchMenuItem;
      public SearchView mSearchView;
      private final Activity _context;
  
      public SearchHolderCompat(final Activity context) {
          _context = context;
      }
  
      public boolean isCurrentyExpanded() {
          return mSearchMenuItem != null &amp;&amp; MenuItemCompat.isActionViewExpanded(mSearchMenuItem);
      }
  
      public boolean hasQuery() {
          return mSearchMenuItem != null &amp;&amp; mSearchView != null &amp;&amp; MenuItemCompat.isActionViewExpanded(mSearchMenuItem)
                  &amp;&amp; !TextUtils.isEmpty(mSearchView.getQuery());
      }
  
      public void addSearchItemAndInit(final Menu menu, final OnQueryTextListener onQueryTextListener,
              final OnActionExpandListener onActionExpandListener) {
          final MenuInflater menuInflater = _context.getMenuInflater();
          menuInflater.inflate(R.menu.search_menu_item, menu);
          init(menu.findItem(R.id.menuItem_search), onQueryTextListener, onActionExpandListener);
      }
  
      public void init(final MenuItem searchMenuItem, final OnQueryTextListener onQueryTextListener,
              final OnActionExpandListener onActionExpandListener) {
          this.mSearchMenuItem = searchMenuItem;
          mSearchView = (SearchView) MenuItemCompat.getActionView(searchMenuItem);
          if (mSearchView == null) {
              MenuItemCompat.setShowAsAction(searchMenuItem, MenuItemCompat.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW
                      | MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
              MenuItemCompat.setActionView(searchMenuItem, mSearchView = new SearchView(_context));
          }
          mSearchView.setQueryHint(_context.getString(R.string.search));
          mSearchView.setOnQueryTextListener(onQueryTextListener);
          MenuItemCompat.setOnActionExpandListener(searchMenuItem, onActionExpandListener);
      }
  
  }
  </code></pre>
  
  <p><strong>MainActivity.java</strong> </p>
  
  <pre><code>public class MainActivity extends ActionBarActivity {
      SearchHolderCompat mSearchHolder = new SearchHolderCompat(this);
  
      @Override
      protected void onCreate(final Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
      }
  
      @Override
      public boolean onCreateOptionsMenu(final Menu menu) {
          mSearchHolder.addSearchItemAndInit(menu, new OnQueryTextListener() {
  
              @Override
              public boolean onQueryTextSubmit(final String arg0) {
                  android.util.Log.d("AppLog", "onQueryTextSubmit");
                  return false;
              }
  
              @Override
              public boolean onQueryTextChange(final String queryText) {
                  android.util.Log.d("AppLog", "onQueryTextChange");
                  return true;
              }
          }, new OnActionExpandListener() {
  
              @Override
              public boolean onMenuItemActionExpand(final MenuItem arg0) {
                  android.util.Log.d("AppLog", "onMenuItemActionExpand");
                  return false;
              }
  
              @Override
              public boolean onMenuItemActionCollapse(final MenuItem arg0) {
                  android.util.Log.d("AppLog", "onMenuItemActionCollapse");
                  return false;
              }
          });
          return true;
      }
  }
  </code></pre>
  
  <p><strong>search_menu_item.xml</strong></p>
  
  <pre><code>&lt;menu xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      xmlns:app="http://schemas.android.com/apk/res-auto" &gt;
  
      &lt;!-- search items --&gt;
      &lt;item
          android:id="@+id/menuItem_search"
          android:icon="@drawable/ic_action_search"
          android:title="@string/search"
          app:actionViewClass="android.support.v7.widget.SearchView"
          app:showAsAction="always"
          tools:ignore="AlwaysShowAction"/&gt;
  
  &lt;/menu&gt;
  </code></pre>
  
  <h2>The question</h2>
  
  <p>What's the correct way to handle the SearchView and the search menu item (using the support library) ? </p>
  
  <p>How come "MenuItemCompat.setOnActionExpandListener" doesn't work?</p>