Show SearchWidget in ActionBar if user presses the device's search button

99封情书 提交于 2019-11-30 19:31:40

While writing this question I came up with the solution by myself. I still decided to post it along with the answer, because it does not seem like this question has been asked on SO before and maybe someone encounters the same problem and/or comes up with a better solution.

All you need to do is call expandActionView() on the search menu item, and everything works like expected:

public boolean onSearchRequested() {
    menu.findItem(R.id.menu_search).expandActionView();
    return true;
} 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!