Expand and give focus to SearchView automatically

后端 未结 17 2445
囚心锁ツ
囚心锁ツ 2020-12-02 18:21

I\'m developing an application where the user presses the \"Search\" icon in the ActionBar and a SearchView is made visible at the top of the scree

17条回答
  •  余生分开走
    2020-12-02 18:45

    use this

    SearchManager searchManager = (SearchManager) mActivity.getSystemService(Context.SEARCH_SERVICE);
                    SearchView searchView = new SearchView(mActivity.actionBar.getThemedContext());
                    searchView.setSearchableInfo(searchManager.getSearchableInfo(mActivity.getComponentName()));
                    searchView.setIconifiedByDefault(false);
                    searchView.setQueryHint("Search");
                    menu.findItem(R.id.action_search).setActionView(searchView);
    

提交回复
热议问题