-1

我的应用程序中有 3 个菜单项和四个选项卡,使用 actionbarsherlock,最初我显示所有菜单项,当我更改选项卡时 2 项应该隐藏,但不知何故它不起作用。下面是我的代码

final static int action_refresh = 0;
    final static int facebook = 1;
    final static int twitter = 2;
    final static int in = 3;

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
       _menuInstance = menu;
        menu.add(1, facebook, 1, "facebook").setIcon(R.drawable.facebook).setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
        menu.add(1, twitter, 2, "twitter").setIcon(R.drawable.twitter).setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
        menu.add(1, in, 3, "in Disk").setIcon(R.drawable.in).setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

        return true;


    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle item selection
        switch (item.getItemId()) {

        case facebook:
             Toast.makeText(this, "Connect on facebook", Toast.LENGTH_SHORT).show();

            return true;
        case twitter:
         Toast.makeText(this, "Connect on twitter", Toast.LENGTH_SHORT).show();

           return true;
        case in:
             Toast.makeText(this, "Connect on Linkedin", Toast.LENGTH_SHORT).show();

              return true;

        default:
            return super.onOptionsItemSelected(item);
        }
    }
    @Override
    public void onTabChanged(int pageIndex, ActionBar.Tab tab, View tabView) {
        resetVisibilityFields();
        if (_menuInstance == null) {
            hideAllActionItems(_menuInstance);

            switch (pageIndex) {
                case 0:
                    showFirstTabActionItems(_menuInstance);
                    break;

                case 1:
                    showSecondTabActionItems(_menuInstance);
                    break;

                case 2:
                    showThirdTabActionItems(_menuInstance);
                    break;

                case 3:
                    showFourthTabActionItems(_menuInstance);
                    break;
            }
        }
    }

我正在尝试隐藏我的第一个选项卡上的图标,如下所示

 private void showFirstTabActionItems(Menu menu) {
        if (menu != null && menu.size() == 2) {

             menu.getItem(1).setVisible(false);
             menu.getItem(3).setVisible(false);


            _firstTabShowed = true;
        }
    }

但它不工作。任何帮助表示赞赏。

4

1 回答 1

0

尝试在onTabUnselected方法上执行此操作

tab.setIcon(null);
于 2014-01-09T03:20:21.840 回答