I’m on the ToolBar Magnifier – search. When you click SearchView disclosed. So I need to make so that it was always open … How to make?
& lt; xml version = "1.0" encoding = "UTF-8"? & gt;
& Lt; menu xmlns: tools = "http://schemas.android.com/tools"
XMLNS: Android = "http://schemas.android.com/apk/res/android"
xmlns: app = "http://schemas.android.com/apk/res-auto" & gt;
& Lt; item
android: id = "@ + id / action_search"
android: title = "Search"
android: icon = "@ drawable / icon_search"
app: showAsAction = "ifRoom | collapseActionView"
app: actionViewClass = "android.support.v7.widget.SearchView"
/ & gt;
& Lt; / menu & gt;
@Override
PROTECTED VOID OnCreate (Bundle SavedInstanceState) {
Super.ONCREATE (SavedInstanceState);
setContentView (R.layout.search_activity);
Toolbar toolbar = (Toolbar) findViewById (R.id.toolbar);
setSupportActionBar (toolbar);
. GetSupportActionBar () setDisplayShowTitleEnabled (false);
getSupportactionBar (). SETDISPLAYHOMEASPENABED (TRUE);
}
Activity:
@ override
Public Boolean OnCreateOptionsMenu (Menu Menu) {
// Inflate The Menu; this adds items to the action bar if it is present.
. GetMenuInflater () inflate (R.menu.main, menu);
SearchManager searchManager =
(SearchManager) getSystemService (Context.SEARCH_SERVICE);
SearchView searchView =
(SearchView) menu.findItem (R.id.action_search) .getActionView ();
searchView.setIconifiedByDefault (false);
searchView.setQueryHint ( "Search");
searchView.setSearchableInfo (
searchManager.getSearchableInfo (getComponentName ()));
RETURN TRUE;
}
Answer 1, Authority 100%
If you want the search field to always be visible, then call setIconifiedByDefault (false).
“If you want to search field was always visible, then the call (use) setIconifiedByDefault (false)”
in the xml
android: iconifiedByDefault = "false"
software:
searchView.setIconified (false);
With regard to your question is: in xml, make sure to stand showAsAction = "always"
and then programmatically change so:
SearchView searchView = (SearchView) menu.findItem (R.id.action_search) .getActionView ();
searchView.setIconifiedByDefault (false);
Answer 2, Authority 33%
The problem was solved:
searchView.setIconifiedByDefault (** true **);
and XML:
app: showAsAction = "always"