Страницы

Поиск по вопросам

вторник, 27 ноября 2018 г.

Как оставить SearchView открытым

У меня на ToolBar лупа - поиска. При клике SearchView раскрывается. Так вот мне нужно сделать так чтобы он всегда был открым... Как сделать?


@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().setDisplayHomeAsUpEnabled(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("Поиск");
searchView.setSearchableInfo( searchManager.getSearchableInfo(getComponentName()));
return true; }


Ответ

Проблема решилась:
searchView.setIconifiedByDefault(**true**);
а в XML:
app:showAsAction="always"

Комментариев нет:

Отправить комментарий