use
searchItem.expandActionView();
and in menu file, use
showAsAction="ifRoom|collapseActionView"
If any query, feel free to comment.
auto open searchin action bar only shows keyboard
-
04-06-2022 - |
Вопрос
I am trying to have the search bar in the actionbar auto open when my search page is launched. I use this to attempt to open the search bar automatically on page open:
@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);
SearchView searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView();
searchView.setIconified(false);
searchView.setOnQueryTextListener(this);
return true;
}
The problem is when the page opens, the keyboard pops up but the search bar does not expand so the user can just start typing the search. It looks like this:
Решение
Другие советы
You can use setIconifiedByDefault(false)
to indicate the default setting
Не связан с StackOverflow