コード例 #1
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_demo);

    Demo demo = getDemo();

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitle(demo.titleResId);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    ViewGroup tab = (ViewGroup) findViewById(R.id.tab);
    tab.addView(LayoutInflater.from(this).inflate(demo.layoutResId, tab, false));

    ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
    SmartTabLayout viewPagerTab = (SmartTabLayout) findViewById(R.id.viewpagertab);
    demo.setup(viewPagerTab);

    FragmentPagerItems pages = new FragmentPagerItems(this);
    for (int titleResId : demo.tabs()) {
      pages.add(FragmentPagerItem.of(getString(titleResId), DemoFragment.class));
    }

    FragmentPagerItemAdapter adapter =
        new FragmentPagerItemAdapter(getSupportFragmentManager(), pages);

    viewPager.setAdapter(adapter);
    viewPagerTab.setViewPager(viewPager);
  }
コード例 #2
0
 @Override
 protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.collection_layout);
   GlobleAtrr.p = this;
   PersonalDemo demo = PersonalDemo.values()[0];
   TextView tv = (TextView) findViewById(R.id.activity_tv_title);
   tv.setText("Hello");
   // GlobleAtrr.a.setSupportActionBar(toolbar);
   // GlobleAtrr.a.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
   ViewGroup tab = (ViewGroup) findViewById(R.id.tab);
   tab.addView(LayoutInflater.from(this).inflate(demo.layoutResId, tab, false));
   ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
   SmartTabLayout viewPagerTab = (SmartTabLayout) findViewById(R.id.viewpagertab);
   demo.setup(viewPagerTab);
   FragmentPagerItems pages = new FragmentPagerItems(this);
   pages.add(FragmentPagerItem.of("0", MyInfoFragment.class));
   pages.add(FragmentPagerItem.of("1", MybookFragment.class));
   FragmentPagerItemAdapter adapter =
       new FragmentPagerItemAdapter(this.getSupportFragmentManager(), pages);
   viewPager.setAdapter(adapter);
   viewPagerTab.setViewPager(viewPager);
 }