Advertisement
Guest User

Tablayout

a guest
Mar 14th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.71 KB | None | 0 0
  1. <TextView
  2. android:id="@+id/textView"
  3. android:layout_width="wrap_content"
  4. android:layout_height="wrap_content"
  5. android:layout_centerInParent="true"
  6. android:text="Tab 1"
  7. android:textAppearance="?android:attr/textAppearanceLarge"/>
  8. ///////////////////////////////////////
  9. public class Tab1 extends Fragment {
  10.  
  11. //Overriden method onCreateView
  12. @Override
  13. public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  14.  
  15. //Returning the layout file after inflating
  16. //Change R.layout.tab1 in you classes
  17. return inflater.inflate(R.layout.tab1, container, false);
  18. }
  19. }
  20. ////////////////////////////////////////
  21. public class Pager extends FragmentStatePagerAdapter {
  22.  
  23. //integer to count number of tabs
  24. int tabCount;
  25.  
  26. //Constructor to the class
  27. public Pager(FragmentManager fm, int tabCount) {
  28. super(fm);
  29. //Initializing tab count
  30. this.tabCount= tabCount;
  31. }
  32.  
  33. //Overriding method getItem
  34. @Override
  35. public Fragment getItem(int position) {
  36. //Returning the current tabs
  37. switch (position) {
  38. case 0:
  39. Tab1 tab1 = new Tab1();
  40. return tab1;
  41. case 1:
  42. Tab2 tab2 = new Tab2();
  43. return tab2;
  44. case 2:
  45. Tab3 tab3 = new Tab3();
  46. return tab3;
  47. default:
  48. return null;
  49. }
  50. }
  51.  
  52. //Overriden method getCount to get the number of tabs
  53. @Override
  54. public int getCount() {
  55. return tabCount;
  56. }
  57. }
  58. /////////////////////////////////////////////main/////
  59. <android.support.v7.widget.Toolbar
  60. android:id="@+id/toolbar"
  61. android:layout_width="match_parent"
  62. android:layout_height="wrap_content"
  63. android:background="?attr/colorPrimary"
  64. android:minHeight="?attr/actionBarSize"
  65. android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
  66. app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
  67.  
  68. <!-- our tablayout to display tabs -->
  69. <android.support.design.widget.TabLayout
  70. android:id="@+id/tabLayout"
  71. android:layout_width="match_parent"
  72. android:layout_height="wrap_content"
  73. android:background="?attr/colorPrimary"
  74. android:minHeight="?attr/actionBarSize"
  75. android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
  76.  
  77. <!-- View pager to swipe views -->
  78. <android.support.v4.view.ViewPager
  79. android:id="@+id/pager"
  80. android:layout_width="match_parent"
  81. android:layout_height="fill_parent"/>
  82.  
  83. ////////////////////////////////////////main
  84. <android.support.v7.widget.Toolbar
  85. android:id="@+id/toolbar"
  86. android:layout_width="match_parent"
  87. android:layout_height="wrap_content"
  88. android:background="?attr/colorPrimary"
  89. android:minHeight="?attr/actionBarSize"
  90. android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
  91. app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
  92.  
  93. <!-- our tablayout to display tabs -->
  94. <android.support.design.widget.TabLayout
  95. android:id="@+id/tabLayout"
  96. android:layout_width="match_parent"
  97. android:layout_height="wrap_content"
  98. android:background="?attr/colorPrimary"
  99. android:minHeight="?attr/actionBarSize"
  100. android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
  101.  
  102. <!-- View pager to swipe views -->
  103. <android.support.v4.view.ViewPager
  104. android:id="@+id/pager"
  105. android:layout_width="match_parent"
  106. android:layout_height="fill_parent"/>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement