Instead of using:
searchItem.collapseActionView();
I have to use the static method from android.support.v4.view.MenuItemCompat :
MenuItemCompat.collapseActionView(searchItem);
It seems obvious at the moment, but it took several hours to think that the available codes on websites, usually designed to work in the library (android.app.ActionBar) (API 11 and above), did not include the V7 Support Library (android. support.v7.app.ActionBar) , which in some cases has its own methods that are different from each other.
source share