How to detect SearchView's back button press?

后端 未结 5 1397
故里飘歌
故里飘歌 2021-02-18 16:39

I\'m using a single activity to display SearchView as well as to display search results. The search results is just a subset of items so the search acts as a filter. Everythin

5条回答
  •  醉话见心
    2021-02-18 17:31

    There is one other trick:

    searchView.setOnSearchViewListener(new MaterialSearchView.SearchViewListener() {
                    @Override
                    public void onSearchViewShown() {
                        if(!txtToolbarTitle.getText().toString().isEmpty()){
                            searchView.setQuery(txtToolbarTitle.getText().toString()+ " ", false);
                        }
                    }
    
                    @Override
                    public void onSearchViewClosed() {
                        if(txtToolbarTitle.getText().toString().isEmpty()){
                            finish();
                        }
                    }
                });
    

提交回复
热议问题