3

我的应用程序中有一个适用于 Android 4.0.3 的操作栏。每个选项卡都有一些按钮(一种继续),它们会更改片段而不是选项卡。我遵循了http://developer.android.com上的官方开发者指南,但它不起作用。

这就是我要的 :

在此处输入图像描述

有可能与 Action Bar Sherlock 进行这种类型的交互吗?

4

1 回答 1

2

I believe you can specify tabs behaviour you need by properly overriding tabs callback class method onTabSelected(Tab tab, FragmentTransaction ft). It shold be look like

        public void onTabSelected(Tab tab, FragmentTransaction ft) {
        // Check if the fragment is already initialized
        if (mFragment == null) {
            // If not, instantiate and add it to the activity
            mFragment = Fragment.instantiate(mActivity, mClass.getName());
            ft.add(R.id.realtabcontent, mFragment, mTag);
        } else {
            //Here we look if current fragment aren't default fragment for this tab
            //Remember that detached fragments are still managed by system, so manage it the way u need
            // If it exists, simply attach it in order to show it
            // ft.attach(mFragment);
            if (mFragment.getTag().equals("defaultFragment"))
                ft.show(mFragment);
            else {
                ft.detach(mFragment);

                mFragment = fragmentManager.findFragmentByTag("defaultFragment");
                if (mFragment == null)
                    mFragment = Fragment.instantiate(mActivity, mClass.getName());
                ft.add(R.id.realtabcontent, mFragment, "defaultFragment");
            }
        }
    }
于 2012-10-15T10:48:29.970 回答