I know this question occurred here a few times, but none of the results helped me.
I want to keep my SearchView always expanded. When I enter the activity it's expanded, when I press the back button for the first time the keyboard goes down (that's ok) and when I press the back button again - the SearchView closes instead of going back to the previous activity.
This is my code in the activity:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_search_series, menu);
// Associate searchable configuration with the SearchView
SearchManager searchManager =
(SearchManager) getSystemService(Context.SEARCH_SERVICE);
// Get the SearchView item
MenuItem item = menu.findItem(R.id.search);
SearchView searchView = (SearchView) item.getActionView();
searchView.setSearchableInfo(
searchManager.getSearchableInfo(new ComponentName(this, SearchSeriesActivity.class)));
// Make it open from the start
item.expandActionView();
searchView.setOnQueryTextListener(this);
return true;
}
This is the xml:
<item android:id="@+id/search"
android:title="@string/action_search_series"
android:icon="@mipmap/ic_search_white"
app:showAsAction="always|collapseActionView"
app:actionViewClass="android.support.v7.widget.SearchView" />
I tried all the solutions:
- Replacing the app:showAsAction to only "always" of only "ifRoom" didn't open it at all.
- Setting the android:iconifiedByDefault to false or true - non of them worked, not in the code also.
Thank you!