Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <TextView
- android:id="@+id/textView"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_centerInParent="true"
- android:text="Tab 1"
- android:textAppearance="?android:attr/textAppearanceLarge"/>
- ///////////////////////////////////////
- public class Tab1 extends Fragment {
- //Overriden method onCreateView
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
- //Returning the layout file after inflating
- //Change R.layout.tab1 in you classes
- return inflater.inflate(R.layout.tab1, container, false);
- }
- }
- ////////////////////////////////////////
- public class Pager extends FragmentStatePagerAdapter {
- //integer to count number of tabs
- int tabCount;
- //Constructor to the class
- public Pager(FragmentManager fm, int tabCount) {
- super(fm);
- //Initializing tab count
- this.tabCount= tabCount;
- }
- //Overriding method getItem
- @Override
- public Fragment getItem(int position) {
- //Returning the current tabs
- switch (position) {
- case 0:
- Tab1 tab1 = new Tab1();
- return tab1;
- case 1:
- Tab2 tab2 = new Tab2();
- return tab2;
- case 2:
- Tab3 tab3 = new Tab3();
- return tab3;
- default:
- return null;
- }
- }
- //Overriden method getCount to get the number of tabs
- @Override
- public int getCount() {
- return tabCount;
- }
- }
- /////////////////////////////////////////////main/////
- <android.support.v7.widget.Toolbar
- android:id="@+id/toolbar"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:background="?attr/colorPrimary"
- android:minHeight="?attr/actionBarSize"
- android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
- app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
- <!-- our tablayout to display tabs -->
- <android.support.design.widget.TabLayout
- android:id="@+id/tabLayout"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:background="?attr/colorPrimary"
- android:minHeight="?attr/actionBarSize"
- android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
- <!-- View pager to swipe views -->
- <android.support.v4.view.ViewPager
- android:id="@+id/pager"
- android:layout_width="match_parent"
- android:layout_height="fill_parent"/>
- ////////////////////////////////////////main
- <android.support.v7.widget.Toolbar
- android:id="@+id/toolbar"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:background="?attr/colorPrimary"
- android:minHeight="?attr/actionBarSize"
- android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
- app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
- <!-- our tablayout to display tabs -->
- <android.support.design.widget.TabLayout
- android:id="@+id/tabLayout"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:background="?attr/colorPrimary"
- android:minHeight="?attr/actionBarSize"
- android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
- <!-- View pager to swipe views -->
- <android.support.v4.view.ViewPager
- android:id="@+id/pager"
- android:layout_width="match_parent"
- android:layout_height="fill_parent"/>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement