SearchView.OnCloseListener does not get invoked

后端 未结 9 619
慢半拍i
慢半拍i 2020-12-03 22:23

Im using an action bar and adding a searchView to it. I have implemented the searchView.onCLoseListener but this does not seem to be getting invoked. Any suggestions ?

9条回答
  •  独厮守ぢ
    2020-12-03 23:01

        MenuItemCompat.OnActionExpandListener expandListener = new MenuItemCompat.OnActionExpandListener() {
            @Override
            public boolean onMenuItemActionCollapse(MenuItem item) {
                // Do something when action item collapses
                /*Hiding the mic on search visibility*/
                    myMenu.findItem(R.id.action_speak).setVisible(false);
                Log.v("test","colllapse");
                return true;  // Return true to collapse action view
            }
    
            @Override
            public boolean onMenuItemActionExpand(MenuItem item) {
                // Do something when expanded
                Log.v("test","expand");
                return true;  // Return true to expand action view
            }
        };
    
        //Searchview Initilisation
        MenuItem searchViewItem = menu.findItem(R.id.action_search);
        // Assign the listener to that action item
        MenuItemCompat.setOnActionExpandListener(searchViewItem, expandListener);
    

    More info from here: https://developer.android.com/training/appbar/action-views.html

提交回复
热议问题