I have SearchView in action bar. It expands when user clicks it and then keyboard appears. This is expected behavior. However, in my app there's one case when I expand SearchView programmatically.
MenuItem searchMenuItem = menu.findItem(R.id.action_search);
MenuItemCompat.expandActionView(searchMenuItem);
I don't want to show keyboard in this case. I expand SearchView programmatically just to show user what was the last search query.
So is it possible to open search view without showing the keyboard?
I resolve my problem using this:
@Override
public void onPrepareOptionsMenu(Menu menu) {
final SearchView searchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.menu_search));
if(!TextUtils.isEmpty(mSearch)){
searchView.setQuery(mSearch, false);
searchView.setIconified(false);
searchView.clearFocus();
}
}
Let me know if this code resolve your problem.
I used below code to expand searchview without opening keyboard:
searchView.setFocusable(false);
searchView.setIconified(false);
searchView.clearFocus();
Hope this helps someone.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With