android searchview setOnActionExpandListener on Honeycomb 3.2

前端 未结 5 1961
無奈伤痛
無奈伤痛 2020-12-15 23:32

I\'m developing an app for Android 3.2 and greater with android-support-v4. I need to implement OnActionExpandListener for \"intercept\" when Searc

5条回答
  •  离开以前
    2020-12-16 00:00

    For MenuItemCompat.setOnActionExpandListener to work you should add "collapseActionView" added in the menu item - for example -

    
    

    And in the onCreateOptionsMenu you can use it this way -

    MenuItemCompat.setOnActionExpandListener(menu_search,
                new OnActionExpandListener()
                {
                    @Override
                    public boolean onMenuItemActionCollapse(MenuItem item)
                    {
                        // Do something when collapsed
                        return true; // Return true to collapse action view
                    }
    
                    @Override
                    public boolean onMenuItemActionExpand(MenuItem item)
                    {
                        // Do something when expanded
                        return true; // Return true to expand action view
                    }
                });
    

提交回复
热议问题