如何从旧的tabhost切换到Android中的滑动选项卡?

时间:2014-03-12 02:26:31

标签: android android-fragments android-tabhost

我目前正在使用旧的tabHost手持一个装满不同片段的手作为标签。如何轻松将其切换到较新的滑动选项卡?

public class StatisticsTab extends Fragment  {


    private FragmentTabHost mTabHost;

    //Mandatory Constructor
    public StatisticsTab() {
    }

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        View rootView = inflater.inflate(R.layout.fragment_tabs,container, false);

        mTabHost = (FragmentTabHost)rootView.findViewById(android.R.id.tabhost);
        mTabHost.setup(getActivity(), getChildFragmentManager(), R.id.realtabcontent);




        mTabHost.addTab(mTabHost.newTabSpec("Basic").setIndicator("Basic"),
                StatisticsPage.class, null);
        mTabHost.addTab(mTabHost.newTabSpec("Brewery").setIndicator("Brewery"),
                BreweryStatistics.class, null);
        mTabHost.addTab(mTabHost.newTabSpec("Style").setIndicator("Style"),
                StyleStatistics.class, null);
        mTabHost.addTab(mTabHost.newTabSpec("Taste").setIndicator("Taste"),
                TasteStatisticsPage.class, null);



        return rootView;
    }




}

1 个答案:

答案 0 :(得分:1)

尝试PagerSlidingTabStriphttps://github.com/astuetz/PagerSlidingTabStrip)。用于在ViewPager的不同页面之间导航的交互式指示器。它对我来说很棒。