I noticed a couple days ago that inputting text in my SearchView
doesn\'t show up. Maybe this problem started longer ago and I hadn\'t noticed it, but I know th
This is the code I use for my recent project and it's work fine:
First define search_menu.xml
(make sure use android supportV7
) :
Then define in your onCreateOptionMenu
of your Activity:
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_search, menu);
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchView searchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.search));
searchView.setSearchableInfo(searchManager.getSearchableInfo(new ComponentName(getApplicationContext(), SearchActivity.class)));
searchView.setMaxWidth(Integer.MAX_VALUE);
MenuItemCompat.expandActionView(menu.findItem(R.id.search));
searchView.setIconifiedByDefault(true);
searchView.setIconified(false);
Also my Toolbar:
Add meta-data to your AndroidManifest.xml
:
Final result: