setOnActionExpandListener

setOnActionExpandListener

本文介绍了不推荐使用MenuItemCompat.setOnActionExpandListener的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些代码可以设置布尔值(无论搜索视图是否打开).

I have some code that sets a boolean if the search view is open or not.

MenuItemCompat.setOnActionExpandListener(action_search, new MenuItemCompat.OnActionExpandListener() {
            @Override
            public boolean onMenuItemActionExpand(MenuItem item){
                isSearch = true;
                return true;
            }
            @Override
            public boolean onMenuItemActionCollapse(MenuItem item){
                isSearch = false;
                return true;
            }
        });

有效.我对它的响应方式感到满意.但是,它显示为已弃用,setOnActionExpandListener被警告删除

It works. I'm happy with the way it responds. However, it it shows as deprecated, the setOnActionExpandListener is crossed out with the warning

建议?

推荐答案

MenuItemCompat.setOnActionExpandListener .此方法已在API级别26.1.0中弃用.

Yes MenuItemCompat.setOnActionExpandListener This method was deprecated in API level 26.1.0.

使用 MenuItem.setOnActionExpandListener(MenuItem.OnActionExpandListener) 直接.

    展开或折叠相关动作view时将通知此菜单项上的
  • MenuItemCompat.OnActionExpandListener . menu item必须配置为使用标志SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW展开或折叠其动作view.

  • MenuItemCompat.OnActionExpandListener on this menu item to be notified when the associated action view is expanded or collapsed. The menu item must be configured to expand or collapse its action view using the flag SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW.

示例代码

MenuItem item = menu.findItem(R.id.action_order);
item.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
     @Override
      public boolean onMenuItemActionExpand(MenuItem menuItem) {
          isSearch = true;
          return true;
      }

      @Override
      public boolean onMenuItemActionCollapse(MenuItem menuItem) {
           isSearch = false;
           return true;
      }
});

这篇关于不推荐使用MenuItemCompat.setOnActionExpandListener的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-12 21:19