I'm facing some problems with a SearchView in a Contextual Action Bar called by a Fragment. The major one is that when my SearchView is expanded, it makes disappear all other items in action bar (except the closing button) even if there's some unused space, like you can see in this screenshot:
Furthermore, I'm also having the same exact problem discussed in this question: ActionBar always expanded SearchView with the icon inside
This is the XML code of my SearchView:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/menu_series_cab_search"
android:icon="@drawable/ic_search"
android:title="@string/action_search"
app:actionViewClass="android.support.v7.widget.SearchView"
app:showAsAction="ifRoom"/>
<item android:id="@+id/action_settings"
android:title="@string/action_settings"
android:orderInCategory="100"
app:showAsAction="never" />
</menu>
And this is the JAVA code of my Fragment that implements ActionMode.Callback
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
mode.getMenuInflater().inflate(R.menu.menu_series_cab, menu);
mSearchView = (SearchView) MenuItemCompat
.getActionView(menu.findItem(R.id.menu_series_cab_search));
mSearchView.setQueryHint(getResources().getString(R.string.action_search));
mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String s) {
mSearchView.clearFocus();
return true;
}
@Override
public boolean onQueryTextChange(String s) {
return false;
}
});
mSearchView.setIconifiedByDefault(false);
return true;
}
@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
mSearchView.requestFocus();
return true;
}
app:showAsAction="always"
and also by removingandroid:orderInCategory="100"
, but no luck. – Breaking