Deprecated MenuItemCompat.setOnActionExpandListener

The function MenuItemCompat.setOnActionExpandListener is deprecated. This function is used to listen for SearchView collapse Events.

An alternative to this is

<span class="typ">MenuItem</span><span class="pln"> menuItemSearch </span><span class="pun">=</span><span class="pln"> menu</span><span class="pun">.</span><span class="pln">findItem</span><span class="pun">(</span><span class="pln">R</span><span class="pun">.</span><span class="pln">id</span><span class="pun">.</span><span class="pln">action_search</span><span class="pun">);</span><span class="pln">

     menuItemSearch</span><span class="pun">.</span><span class="pln">setOnActionExpandListener</span><span class="pun">(</span><span class="kwd">new</span><span class="typ">MenuItem</span><span class="pun">.</span><span class="typ">OnActionExpandListener</span><span class="pun">()</span><span class="pun">{</span><span class="lit">@Override</span><span class="kwd">public</span><span class="kwd">boolean</span><span class="pln"> onMenuItemActionExpand</span><span class="pun">(</span><span class="typ">MenuItem</span><span class="pln"> menuItem</span><span class="pun">)</span><span class="pun">{</span><span class="pln">
            isSearch </span><span class="pun">=</span><span class="kwd">true</span><span class="pun">;</span><span class="kwd">return</span><span class="kwd">true</span><span class="pun">;</span><span class="pun">}</span><span class="lit">@Override</span><span class="kwd">public</span><span class="kwd">boolean</span><span class="pln"> onMenuItemActionCollapse</span><span class="pun">(</span><span class="typ">MenuItem</span><span class="pln"> menuItem</span><span class="pun">)</span><span class="pun">{</span><span class="pln">
            isSearch </span><span class="pun">=</span><span class="kwd">false</span><span class="pun">;</span><span class="kwd">return</span><span class="kwd">true</span><span class="pun">;</span><span class="pun">}</span><span class="pun">});</span>```

 

StackOverflow Link : [https://stackoverflow.com/questions/48989235/menuitemcompat-setonactionexpandlistener-deprecated](https://stackoverflow.com/questions/48989235/menuitemcompat-setonactionexpandlistener-deprecated)