{"id":52208,"date":"2017-11-27T11:00:26","date_gmt":"2017-11-27T09:00:26","guid":{"rendered":"http:\/\/examples.javacodegeeks.com\/?p=52208"},"modified":"2019-04-24T11:30:20","modified_gmt":"2019-04-24T08:30:20","slug":"android-tablayout-example","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/android\/core\/widget\/android-tablayout-example\/","title":{"rendered":"Android TabLayout Example"},"content":{"rendered":"<h2>1. Introduction<\/h2>\n<p>In this example, we will be going through the process of creating a basic user interface using the tab layout constructs available on the Android platform. In Android, the <code>TabLayout<\/code> is a construct for better organizing a user interface. It does so by making the user interface more organized and less cluttered.<\/p>\n<p>This example will also explain the different&nbsp;aspect which makes an android application briefly. These aspects include the XML&nbsp;configuration of an android application, the basics of Android activities, the manifest file and some of Gradle&nbsp;basic&nbsp;usages and features in an Android context.<\/p>\n<p>At the end of this article, we will have a working example build using Android Studio, Gradle, The Android SDK which in our case will come packaged with Android Studio.\n<\/p>\n<h2>2. Technologies used<\/h2>\n<ul>\n<li>Android Studio 3<\/li>\n<li>Android 7.1.1 (Nougat):&nbsp; API 25<\/li>\n<li>Android Virtual Device: Nexus 5X.<\/li>\n<\/ul>\n<h2>3. Create a Fragment<\/h2>\n<p>Below is the very first step when creating a fragment in Android Studio.<\/p>\n<p><figure id=\"attachment_52434\" aria-describedby=\"caption-attachment-52434\" style=\"width: 860px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/11\/creating-fragment-1.png\"><img decoding=\"async\" class=\"wp-image-52434 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/11\/creating-fragment-1.png\" alt=\"\" width=\"860\" height=\"432\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/11\/creating-fragment-1.png 860w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/11\/creating-fragment-1-300x151.png 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/11\/creating-fragment-1-768x386.png 768w\" sizes=\"(max-width: 860px) 100vw, 860px\" \/><\/a><figcaption id=\"caption-attachment-52434\" class=\"wp-caption-text\">This is the first step in creating a fragment in Android studio.<\/figcaption><\/figure><\/p>\n<p>Below is the second step when creating a fragment in Android Studio.<\/p>\n<p><figure id=\"attachment_52446\" aria-describedby=\"caption-attachment-52446\" style=\"width: 550px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/11\/creating-fragment-2.png\"><img decoding=\"async\" class=\"wp-image-52446 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/11\/creating-fragment-2.png\" alt=\"\" width=\"550\" height=\"460\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/11\/creating-fragment-2.png 550w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/11\/creating-fragment-2-300x251.png 300w\" sizes=\"(max-width: 550px) 100vw, 550px\" \/><\/a><figcaption id=\"caption-attachment-52446\" class=\"wp-caption-text\">This is the second step in creating a fragment in Android studio.<\/figcaption><\/figure><\/p>\n<h2>4. Implement the First Fragment class<\/h2>\n<p>Below is a basic implementation of a fragment. In this Fragment all we are basically doing is setting the layout which must be rendered when this fragment loads. This concept applies to all the other fragments implementations in this articles namely <code>SecondFragment<\/code> and <code>ThirdFragment<\/code><\/p>\n<p><span style=\"text-decoration: underline\"><em>FirstFragment.java<\/em><\/span><\/p>\n<pre class=\"brush:java; highlight:[2,3,4,5,6,8,10,13]\">package com.tablelayout.javacodegeeks.tablayoutexample;\nimport android.os.Bundle;\nimport android.support.v4.app.Fragment;\nimport android.view.LayoutInflater;\nimport android.view.View;\nimport android.view.ViewGroup;\n\npublic class FirstFragment extends Fragment {\n    @Override\n    public View onCreateView(LayoutInflater inflater, ViewGroup container,\n                             Bundle savedInstanceState) {\n        \/\/ Inflate the layout for this fragment\n        return inflater.inflate(R.layout.fragment_first, container, false);\n    }\n}\n<\/pre>\n<ul>\n<li>line 2 to 6: we import all the required dependencies for this class.<\/li>\n<li>line 8: we define the <code>FirstFragment<\/code>&nbsp;Class which extends the <code>Fragment<\/code> supper class from the Android platform.<\/li>\n<li>line 10: we override the <code>onCreateView<\/code>&nbsp;Method from the <code>Fragment<\/code> superclass. This method is a lifecycle method that gets executed when the Fragment component is been loaded for the first time.<\/li>\n<li>line 13: we use the <code>LayoutInflater<\/code> component to register our XML layout configuration with the rest of the application. This is accomplished by calling the <code>inflate<\/code> method of the <code>inflater<\/code>&nbsp;object and passing to the <code>fragment_first<\/code> as its layout definition.<\/li>\n<\/ul>\n<h2>5. Implement the Second Fragment class<\/h2>\n<p><span style=\"text-decoration: underline\"><em>SecondFragment.java<\/em><\/span><\/p>\n<pre class=\"brush:java; highlight:[2,3,4,5,6,8,10,13]\">package com.tablelayout.javacodegeeks.tablayoutexample;\nimport android.support.v4.app.Fragment;\nimport android.view.LayoutInflater;\nimport android.view.View;\nimport android.view.ViewGroup;\n\npublic class SecondFragment extends Fragment {\n    @Override\n    public View onCreateView(LayoutInflater inflater, ViewGroup container,\n                             Bundle savedInstanceState) {\n        \/\/ Inflate the layout for this fragment\n        return inflater.inflate(R.layout.fragment_second, container, false);\n    }\n}\n<\/pre>\n<ul>\n<li>line 2 to 6: we import all the required dependencies for this class.<\/li>\n<li>line 8: we define the <code>SecondFragment<\/code>&nbsp;Class which extends the <code>Fragment<\/code> supper class from the Android platform.<\/li>\n<li>line 10: we override the <code>onCreateView<\/code>&nbsp;Method from the <code>Fragment<\/code> superclass. This method is a lifecycle method that gets executed when the Fragment component is been loaded for the first time.<\/li>\n<li>line 13: we use the <code>LayoutInflater<\/code> component to register our XML layout configuration with the rest of the application. This is accomplished by calling the <code>inflate<\/code> method of the <code>inflater<\/code>&nbsp;object and passing to the <code>fragment_second<\/code> as its layout definition.<\/li>\n<\/ul>\n<h2>6. Implement the Third Fragment class<\/h2>\n<p><span style=\"text-decoration: underline\"><em>ThirdFragment.java<\/em><\/span><div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<pre class=\"brush:java; highlight:[2,3,4,5,6,8,10,13]\">package com.tablelayout.javacodegeeks.tablayoutexample;\nimport android.os.Bundle;\nimport android.support.v4.app.Fragment;\nimport android.view.LayoutInflater;\nimport android.view.View;\nimport android.view.ViewGroup;\n\npublic class ThirdFragment extends Fragment {\n    @Override\n    public View onCreateView(LayoutInflater inflater, ViewGroup container,\n                             Bundle savedInstanceState) {\n        \/\/ Inflate the layout for this fragment\n        return inflater.inflate(R.layout.fragment_third, container, false);\n    }\n}\n<\/pre>\n<ul>\n<li>line 2 to 6: we import all the required dependencies for this class.<\/li>\n<li>line 8: we define the <code>ThirdFragment<\/code>&nbsp;Class which extends the <code>Fragment<\/code> supper class from the Android platform.<\/li>\n<li>line 10: we override the <code>onCreateView<\/code>&nbsp;Method from the <code>Fragment<\/code> superclass. This method is a lifecycle method that gets executed when the Fragment component is been loaded for the first time.<\/li>\n<li>line 13: we use the <code>LayoutInflater<\/code> component to register our XML layout configuration with the rest of the application. This is accomplished by calling the <code>inflate<\/code> method of the <code>inflater<\/code>&nbsp;object and passing to the <code>fragment_third<\/code> as its layout definition.<\/li>\n<\/ul>\n<h2>7. Fragment Layouts<\/h2>\n<p>Below is the corresponding xml layout configuration for all 3 fragments respectively. All that&#8217;s happening in a nutshell is, we are defining a text that will get displayed whenever we are on the correct tab. For example when we are on the First Tab, the&nbsp;First Tab text will be displayed in its body. This is accomplished by using the <code>TextView<\/code> tag and its <code>text<\/code>property.<\/p>\n<p>Below is the first fragment s layout file.<\/p>\n<p><figure id=\"attachment_52444\" aria-describedby=\"caption-attachment-52444\" style=\"width: 860px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/11\/first-fragment-layout.png\"><img decoding=\"async\" class=\"wp-image-52444 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/11\/first-fragment-layout.png\" alt=\"\" width=\"860\" height=\"193\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/11\/first-fragment-layout.png 860w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/11\/first-fragment-layout-300x67.png 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/11\/first-fragment-layout-768x172.png 768w\" sizes=\"(max-width: 860px) 100vw, 860px\" \/><\/a><figcaption id=\"caption-attachment-52444\" class=\"wp-caption-text\">This is the first fragment s layout file.<\/figcaption><\/figure><\/p>\n<p>Below is the second fragment s layout file.<\/p>\n<p><figure id=\"attachment_52438\" aria-describedby=\"caption-attachment-52438\" style=\"width: 860px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/11\/second-fragment-layout.png\"><img decoding=\"async\" class=\"wp-image-52438 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/11\/second-fragment-layout.png\" alt=\"\" width=\"860\" height=\"192\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/11\/second-fragment-layout.png 860w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/11\/second-fragment-layout-300x67.png 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/11\/second-fragment-layout-768x171.png 768w\" sizes=\"(max-width: 860px) 100vw, 860px\" \/><\/a><figcaption id=\"caption-attachment-52438\" class=\"wp-caption-text\">This is the second fragment s layout file.<\/figcaption><\/figure><\/p>\n<p>Below is the third fragment s layout file.<\/p>\n<p><figure id=\"attachment_52436\" aria-describedby=\"caption-attachment-52436\" style=\"width: 860px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/11\/third-fragment-layout.png\"><img decoding=\"async\" class=\"wp-image-52436 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/11\/third-fragment-layout.png\" alt=\"\" width=\"860\" height=\"186\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/11\/third-fragment-layout.png 860w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/11\/third-fragment-layout-300x65.png 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/11\/third-fragment-layout-768x166.png 768w\" sizes=\"(max-width: 860px) 100vw, 860px\" \/><\/a><figcaption id=\"caption-attachment-52436\" class=\"wp-caption-text\">This is the third fragment s layout file.<\/figcaption><\/figure><\/p>\n<h2>8. Implement the PagerAdapter class<\/h2>\n<p>In order for us to manage all our defined fragments as a single unit, we need to implement an adapter which will help us configure our Fragments from the client application.<\/p>\n<p>Below is our implementation of a <code>FragmentPagerAdapter<\/code><\/p>\n<p><span style=\"text-decoration: underline\"><em>PagerAdapter.java<\/em><\/span><\/p>\n<pre class=\"brush:java; highlight:[1,4,6,7,8,10,14,15,26,31]\">package com.tablelayout.javacodegeeks.tablayoutexample;\nimport android.support.v4.app.Fragment;\nimport android.support.v4.app.FragmentManager;\nimport android.support.v4.app.FragmentPagerAdapter;\n\npublic class PagerAdapter extends FragmentPagerAdapter {\n    int numberOfTabs;\n    public PagerAdapter(FragmentManager fm, int NumOfTabs) {\n        super(fm);\n        this.numberOfTabs = NumOfTabs;\n    }\n\n    @Override\n    public Fragment getItem(int position) {\n        switch (position) {\n            case 0:\n                FirstFragment tab1 = new FirstFragment();\n                return tab1;\n            case 1:\n                SecondFragment tab2 = new SecondFragment();\n                return tab2;\n            case 2:\n                ThirdFragment tab3 = new ThirdFragment();\n                return tab3;\n            default:\n                return null;\n        }\n    }\n\n    @Override\n    public int getCount() {\n        return numberOfTabs;\n    }\n}\n<\/pre>\n<ul>\n<li>line 1 to 4: we import all the required dependencies for this class.<\/li>\n<li>line 6: we define the <code>PagerAdapter<\/code>&nbsp;Class which extends the <code>FragmentPagerAdapter<\/code> supper class from the Android platform.<\/li>\n<li>line 7: we define the <code>numberOfTabs<\/code> variable to hold the tab number<\/li>\n<li>line 8 to 10: we define the constructor which will help initialize the <code>FragmentManager<\/code> and the <code>numberOfTabs<\/code><\/li>\n<li>line 14: we override the <code>getItem<\/code> method of the <code>FragmentPagerAdapter<\/code> super class<\/li>\n<li>line 15 to 26: we define the logic via a switch statement which will be responsible fo assigning the right Fragment to correct Tab.<\/li>\n<li>line 31: we override the <code>getCount<\/code> method of the <code>FragmentPagerAdapter<\/code> class, so that the client code could determine the number of tabs beforehand.<\/li>\n<\/ul>\n<h2>9. Implement the MainActivity class<\/h2>\n<p>Any Android or even Java application must always have an entry point. This is why we have to create the <code>MainActivity<\/code> class which will be in our example, the entry point to the application.[ulp id=&#8217;Ja8Orb5oPKdShcXt&#8217;]<\/p>\n<p><span style=\"text-decoration: underline\"><em>MainActivity.java<\/em><\/span><\/p>\n<pre class=\"brush:java; highlight:[2,5,7,9,10,11,13,17,19,39]\">package com.tablelayout.javacodegeeks.tablayoutexample;\nimport android.support.v4.view.ViewPager;\nimport android.support.v7.app.AppCompatActivity;\nimport android.os.Bundle;\nimport android.support.design.widget.TabLayout;\n\npublic class MainActivity extends AppCompatActivity {\n    @Override\n    protected void onCreate(Bundle savedInstanceState) {\n        super.onCreate(savedInstanceState);\n        setContentView(R.layout.activity_main);\n\n        TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);\n        tabLayout.addTab(tabLayout.newTab().setText(\"First Tab\"));\n        tabLayout.addTab(tabLayout.newTab().setText(\"Second Tab\"));\n        tabLayout.addTab(tabLayout.newTab().setText(\"Third Tab\"));\n        tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);\n\n        final ViewPager viewPager = (ViewPager) findViewById(R.id.pager);\n        final PagerAdapter adapter = new PagerAdapter\n                (getSupportFragmentManager(), tabLayout.getTabCount());\n        viewPager.setAdapter(adapter);\n        viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));\n        tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {\n            @Override\n            public void onTabSelected(TabLayout.Tab tab) {\n                viewPager.setCurrentItem(tab.getPosition());\n            }\n\n            @Override\n            public void onTabUnselected(TabLayout.Tab tab) {\n            }\n\n            @Override\n            public void onTabReselected(TabLayout.Tab tab) {\n            }\n        });\n    }\n}<\/pre>\n<ul>\n<li>line 2 to 5: we import all the required dependencies for this class.<\/li>\n<li>line 7: we define the <code>MainActivity<\/code> class which will be the entry point to our application. This class extends the <code>AppCompatActivity<\/code> class from the android platform.<\/li>\n<li>line 9: we override the <code>onCreate<\/code> method of the <code>AppCompatActivity<\/code> class. This method is a lifecycle method and it gets excecuted only once and that is when the application loads up for the first time.<\/li>\n<li>line 10: we call the <code>onCreate<\/code> method of the <code>AppCompatActivity<\/code> class in order to save the state of our activity each time we close the application<\/li>\n<li>line 11: we set the content view of the activity to the <code>activity_main<\/code> layout.<\/li>\n<li>line 13 to 17: we define the tab layout using the <code>TabLayout<\/code> class and the <code>tab_layout<\/code> definition from the <code>activity_main<\/code>layout. Next, we add tabs to the layout. Then the Gravity.<\/li>\n<li>line 19 to 39: here we define the view pager for our tab layout. The very first step in this process is to load the pager configuration from the main activities layout. Then instantiate an object of the <code>PagerAdapter<\/code> class which will be used to set the number of Tabs most importantly. Once the pager adapter object has been instantiated we have to use the <code>ViewPager<\/code>&#8216;s setAdapter method to register the adapter with the view pager. Afterward we have to add a page change listener using the <code>addOnPageChangeListener<\/code> method of the viewPager. The last step is to add a <code>TabSelectedListener<\/code> using the <code>addOnTabSelectedListener<\/code> of the tabLayout object.<\/li>\n<\/ul>\n<h2>10. MainActivity Layout<\/h2>\n<p>Main activity s layout file&nbsp;<code>activity_main.xml<\/code> contains all the layout definitions for the <code>MainActivity<\/code>. In this layout the few things that happen are:<\/p>\n<ul>\n<li>We create a TabLayout component using the <code>TabLayout<\/code> tag. Then we add some basic properties to align the view.<\/li>\n<li>We create a ViewPager component using the <code>ViewPagerTag<\/code> tag. Then we add some basic properties to align the view<\/li>\n<\/ul>\n<p><figure id=\"attachment_52442\" aria-describedby=\"caption-attachment-52442\" style=\"width: 860px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/11\/main-activity-layout.png\"><img decoding=\"async\" class=\"wp-image-52442 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/11\/main-activity-layout.png\" alt=\"\" width=\"860\" height=\"310\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/11\/main-activity-layout.png 860w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/11\/main-activity-layout-300x108.png 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/11\/main-activity-layout-768x277.png 768w\" sizes=\"(max-width: 860px) 100vw, 860px\" \/><\/a><figcaption id=\"caption-attachment-52442\" class=\"wp-caption-text\">This is the MainActivity s layout file.<\/figcaption><\/figure><\/p>\n<h2>11. Final Application<\/h2>\n<p>Below is a screenshot of the final running application.<\/p>\n<p><figure id=\"attachment_52440\" aria-describedby=\"caption-attachment-52440\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/11\/running-fragment-app.png\"><img decoding=\"async\" class=\"wp-image-52440 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/11\/running-fragment-app.png\" alt=\"\" width=\"300\" height=\"555\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/11\/running-fragment-app.png 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/11\/running-fragment-app-162x300.png 162w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><figcaption id=\"caption-attachment-52440\" class=\"wp-caption-text\">The final running application.<\/figcaption><\/figure><\/p>\n<h2>12. Conclusion<\/h2>\n<p>In this example, we&#8217;ve seen our to create a tab layout user interface. We did all this by creating Fragments, a PagerAdapter and a MainActivity to wire everything together into an android application.<\/p>\n<p>We also learned a bit about lifecycle methods of fragments and pager adapters. We have intentionally omitted the Manifest file explanation due to the length of the example and the fact it falls more as a general android construct.<\/p>\n<h2>13. Download the Source Code<\/h2>\n<p>That was Android TabLayout Example.<\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the full source code of this example here: <a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/11\/TabLayoutExample-1.zip\"><strong>TabLayoutExample<\/strong><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>1. Introduction In this example, we will be going through the process of creating a basic user interface using the tab layout constructs available on the Android platform. In Android, the TabLayout is a construct for better organizing a user interface. It does so by making the user interface more organized and less cluttered. This &hellip;<\/p>\n","protected":false},"author":139,"featured_media":1202,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[521],"tags":[],"class_list":["post-52208","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-widget"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Android TabLayout Example - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"1. Introduction In this example, we will be going through the process of creating a basic user interface using the tab layout constructs available on the\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/examples.javacodegeeks.com\/android\/core\/widget\/android-tablayout-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Android TabLayout Example - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"1. Introduction In this example, we will be going through the process of creating a basic user interface using the tab layout constructs available on the\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/android\/core\/widget\/android-tablayout-example\/\" \/>\n<meta property=\"og:site_name\" content=\"Examples Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2017-11-27T09:00:26+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-04-24T08:30:20+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Georges Sofo\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Georges Sofo\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/widget\/android-tablayout-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/widget\/android-tablayout-example\/\"},\"author\":{\"name\":\"Georges Sofo\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/8a230efff71f2ecde6491d3e814b6b9e\"},\"headline\":\"Android TabLayout Example\",\"datePublished\":\"2017-11-27T09:00:26+00:00\",\"dateModified\":\"2019-04-24T08:30:20+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/widget\/android-tablayout-example\/\"},\"wordCount\":1291,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/widget\/android-tablayout-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg\",\"articleSection\":[\"widget\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/android\/core\/widget\/android-tablayout-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/widget\/android-tablayout-example\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/widget\/android-tablayout-example\/\",\"name\":\"Android TabLayout Example - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/widget\/android-tablayout-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/widget\/android-tablayout-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg\",\"datePublished\":\"2017-11-27T09:00:26+00:00\",\"dateModified\":\"2019-04-24T08:30:20+00:00\",\"description\":\"1. Introduction In this example, we will be going through the process of creating a basic user interface using the tab layout constructs available on the\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/widget\/android-tablayout-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/android\/core\/widget\/android-tablayout-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/widget\/android-tablayout-example\/#primaryimage\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/android\/core\/widget\/android-tablayout-example\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/examples.javacodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Android\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/android\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"core\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/android\/core\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"widget\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/android\/core\/widget\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"Android TabLayout Example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Examples and Code Snippets\",\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/javacodegeeks\",\"https:\/\/x.com\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/8a230efff71f2ecde6491d3e814b6b9e\",\"name\":\"Georges Sofo\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/11\/Georges-Sofo_avatar_1510659183-96x96.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/11\/Georges-Sofo_avatar_1510659183-96x96.jpg\",\"caption\":\"Georges Sofo\"},\"description\":\"Georges Albert Sofo is a bachelors degree holder in software development, more specifically using Java technologies and following the OOP paradigm approach to software development. he has being working as a full time Software Engineer for more than 4 years, at companies ranging from telecommunication, consultancy, financial institution and educational type companies. His current focus lies in anything Java (Spring Framework preferably) on the backend and Javascript on the Frontend.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/georges-sofo\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Android TabLayout Example - Java Code Geeks","description":"1. Introduction In this example, we will be going through the process of creating a basic user interface using the tab layout constructs available on the","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/examples.javacodegeeks.com\/android\/core\/widget\/android-tablayout-example\/","og_locale":"en_US","og_type":"article","og_title":"Android TabLayout Example - Java Code Geeks","og_description":"1. Introduction In this example, we will be going through the process of creating a basic user interface using the tab layout constructs available on the","og_url":"https:\/\/examples.javacodegeeks.com\/android\/core\/widget\/android-tablayout-example\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2017-11-27T09:00:26+00:00","article_modified_time":"2019-04-24T08:30:20+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg","type":"image\/jpeg"}],"author":"Georges Sofo","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Georges Sofo","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/widget\/android-tablayout-example\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/widget\/android-tablayout-example\/"},"author":{"name":"Georges Sofo","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/8a230efff71f2ecde6491d3e814b6b9e"},"headline":"Android TabLayout Example","datePublished":"2017-11-27T09:00:26+00:00","dateModified":"2019-04-24T08:30:20+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/widget\/android-tablayout-example\/"},"wordCount":1291,"commentCount":0,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/widget\/android-tablayout-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg","articleSection":["widget"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/android\/core\/widget\/android-tablayout-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/widget\/android-tablayout-example\/","url":"https:\/\/examples.javacodegeeks.com\/android\/core\/widget\/android-tablayout-example\/","name":"Android TabLayout Example - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/widget\/android-tablayout-example\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/widget\/android-tablayout-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg","datePublished":"2017-11-27T09:00:26+00:00","dateModified":"2019-04-24T08:30:20+00:00","description":"1. Introduction In this example, we will be going through the process of creating a basic user interface using the tab layout constructs available on the","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/widget\/android-tablayout-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/android\/core\/widget\/android-tablayout-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/widget\/android-tablayout-example\/#primaryimage","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/android-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/examples.javacodegeeks.com\/android\/core\/widget\/android-tablayout-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/examples.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Android","item":"https:\/\/examples.javacodegeeks.com\/category\/android\/"},{"@type":"ListItem","position":3,"name":"core","item":"https:\/\/examples.javacodegeeks.com\/category\/android\/core\/"},{"@type":"ListItem","position":4,"name":"widget","item":"https:\/\/examples.javacodegeeks.com\/category\/android\/core\/widget\/"},{"@type":"ListItem","position":5,"name":"Android TabLayout Example"}]},{"@type":"WebSite","@id":"https:\/\/examples.javacodegeeks.com\/#website","url":"https:\/\/examples.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Examples and Code Snippets","publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/examples.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/examples.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/8a230efff71f2ecde6491d3e814b6b9e","name":"Georges Sofo","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/11\/Georges-Sofo_avatar_1510659183-96x96.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/11\/Georges-Sofo_avatar_1510659183-96x96.jpg","caption":"Georges Sofo"},"description":"Georges Albert Sofo is a bachelors degree holder in software development, more specifically using Java technologies and following the OOP paradigm approach to software development. he has being working as a full time Software Engineer for more than 4 years, at companies ranging from telecommunication, consultancy, financial institution and educational type companies. His current focus lies in anything Java (Spring Framework preferably) on the backend and Javascript on the Frontend.","url":"https:\/\/examples.javacodegeeks.com\/author\/georges-sofo\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/52208","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/users\/139"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=52208"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/52208\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media\/1202"}],"wp:attachment":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=52208"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=52208"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=52208"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}