How to detect SearchView's back button press?

后端 未结 5 1406
故里飘歌
故里飘歌 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:32

    All code here is deprecated ! You should use something like this.

    final MenuItem item = menu.findItem(R.id.action_search);
    final SearchView searchView = (SearchView) item.getActionView();
    
    item.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
    
                @Override
                public boolean onMenuItemActionExpand(MenuItem item) {
                    Toast.makeText(getActivity(), "onMenuItemActionExpand called", Toast.LENGTH_SHORT).show();
                    return true;
                }
    
                @Override
                public boolean onMenuItemActionCollapse(MenuItem item) {
                    Toast.makeText(getActivity(), "onMenutItemActionCollapse called", Toast.LENGTH_SHORT).show();
                    return true;
                }
            });
    

    Hope that will help.

提交回复
热议问题