其他分享
首页 > 其他分享> > 强制在SearchView上图标化

强制在SearchView上图标化

作者:互联网

我在操作栏中有一个SearchView,现在它完全可以正常工作,无论如何,当我单击提交按钮(即查询已提交并显示结果)时,当我返回到从其开始的活动时,它都会出现一个问题.从SearchView搜索扩大了,我的问题是如何关闭它,即在提交时将其图标化.这是我的代码.

searchView = (SearchView) item.getActionView();
            SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
            searchView.setSearchableInfo(searchManager
                    .getSearchableInfo(getComponentName()));
            searchView.setIconifiedByDefault(true);
            searchView.setIconified(true);
            searchView.setQueryRefinementEnabled(true);
            searchView
                    .setOnQueryTextListener(new SearchView.OnQueryTextListener() {

                        @Override
                        public boolean onQueryTextSubmit(String query) {
                            try {
                                  searchView = (SearchView) item.getActionView();
        SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
        searchView.setSearchableInfo(searchManager
                .getSearchableInfo(getComponentName()));
        searchView.setIconifiedByDefault(true);
        searchView.setIconified(true);
        searchView.setQueryRefinementEnabled(true);
        searchView
                .setOnQueryTextListener(new SearchView.OnQueryTextListener() {

                    @Override
                    public boolean onQueryTextSubmit(String query) {
                        try {

                        } catch (Exception ex) {
                            ex.printStackTrace();
                        }
                        return false;
                    }

                    @Override
                    public boolean onQueryTextChange(String newText) {
                        // TODO Auto-generated method stub
                        return false;
                    }
                }); // doesnot work 
                            } catch (Exception ex) {
                                ex.printStackTrace();
                            }
                            return false;
                        }

                        @Override
                        public boolean onQueryTextChange(String newText) {
                            // TODO Auto-generated method stub
                            return false;
                        }
                    });

解决方法:

对于API> = 14,您可以使用item.collapseActionView().

标签:actionbarsherlock,searchview,android
来源: https://codeday.me/bug/20191031/1977436.html