滑动标签中的碎片

时间:2015-05-12 20:10:10

标签: android slidingmenu

如果我以这种方式实现滑动标签:

MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    MyApplication.setActivity(this);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mToolbar = (Toolbar) findViewById(R.id.tool_bar);
    setSupportActionBar(mToolbar);

    mViewPagerAdapter =  new ViewPagerAdapter(getSupportFragmentManager(),Titles, mNumOfTabs);

    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mViewPagerAdapter);


    mSlidingTabs = (SlidingTabLayout) findViewById(R.id.tabs);
    mSlidingTabs.setDistributeEvenly(true); 

    mSlidingTabs.setCustomTabColorizer(new SlidingTabLayout.TabColorizer() {
        @Override
        public int getIndicatorColor(int position) {
            return getResources().getColor(R.color.tabScrollColor);
        }
    });

    // Setting the ViewPager For the SlidingTabsLayout
    mSlidingTabs.setViewPager(mViewPager);



}

ViewPagerAdapter.java

public class ViewPagerAdapter extends FragmentStatePagerAdapter {

    CharSequence Titles[];
    int mNumbOfTabs;

    public ViewPagerAdapter(FragmentManager fm,CharSequence mTitles[], int mNumbOfTabsumb) {
        super(fm);

        this.Titles = mTitles;
        this.mNumbOfTabs = mNumbOfTabsumb;

    }

    public ViewPagerAdapter(FragmentManager fm,CharSequence mTitles[], int mNumbOfTabsumb, Integer hashId) {
        super(fm);

        this.Titles = mTitles;
        this.mNumbOfTabs = mNumbOfTabsumb;
    }

    @Override
    public Fragment getItem(int position) {

        if(mNumbOfTabs == 2) {
            if (position == 0) {
                AFragment a = new AFragment();
                return a;
            } else if (position == 1) {
                BFragment b = new BFragment();
                return b;
            } 
        }     

    @Override
    public CharSequence getPageTitle(int position) {
        return Titles[position];
    }

    @Override
    public int getCount() {
        return mNumbOfTabs;
    }
}

如何实现这样的东西 - 例如当我单击其中一个滑动标签中的按钮,滑动标签消失并创建覆盖整个屏幕的新片段?对不起基本知识,但我只是在学习。

0 个答案:

没有答案