问题
I have an ActionBar with a SearchView.
I want the search view to always be "open" (expanded). Doing that is possible using
mSearchView.setIconifiedByDefault(false);
But it for some reason moves the search icon outside of the text area:

If I don't use setIconifiedByDefault(), it looks like I want it to look when it is expanded:

But then it collapses into a search icon on back, and also
MenuItemCompat.expandActionView(searchItem);
Does not seem to help.
Is there a way to achieve what I want?
回答1:
You can just intercept OnClose event:
searchView.setOnCloseListener(new SearchView.OnCloseListener() {
@Override
public boolean onClose() {
return true;
}
});
回答2:
I was able to solve this issue by changing my XML from
<item android:id="@+id/search"
android:icon="@drawable/my_icon"
app:showAsAction="always|collapseActionView"
app:actionViewClass="android.support.v7.widget.SearchView" />
to
<item android:id="@+id/search"
android:icon="@drawable/my_icon"
app:showAsAction="always"
app:actionViewClass="android.support.v7.widget.SearchView" />
来源:https://stackoverflow.com/questions/24757591/actionbar-always-expanded-searchview-with-the-icon-inside