Show android SearchView EditText by default

梦想的初衷 提交于 2019-12-01 08:31:35

EDIT---

Oh sorry! I tought you wanted to do an 'empty' query. I think you can open SearchView programmatically using:

searchView.setIconified(false);

OLD ANSWER--

Inside an Activity you can try with:

onSearchRequested();

And inside a Fragment you can try with:

getActivity().onSearchRequested();

Good luck!

From the official Android docs:

If you want the search field to always be visible, then call setIconifiedByDefault(false).

This does work for the compatibility android.support.v7.widget.SearchView as well.

You can try this:

SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
// Expand the search view
searchItem.expandActionView();

Thanks.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!