Skip to content

Instantly share code, notes, and snippets.

@codeamt
Created September 26, 2018 06:51
Show Gist options
  • Save codeamt/0b5f232a7a908333c76909c9befc4c00 to your computer and use it in GitHub Desktop.
Save codeamt/0b5f232a7a908333c76909c9befc4c00 to your computer and use it in GitHub Desktop.
private void inflateTabs(Sandwich sandwich) {
toolbar = (android.support.v7.widget.Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);
tabLayout.addTab(tabLayout.newTab().setText("Background"));
tabLayout.addTab(tabLayout.newTab().setText("Ingredients"));
tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
final ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
final PagerAdapter adapter = new PagerAdapter(getSupportFragmentManager(), tabLayout.getTabCount());
viewPager.setAdapter(adapter);
viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
tabLayout.addOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(viewPager));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment