{"id":1415,"date":"2016-04-22T05:29:46","date_gmt":"2016-04-22T05:29:46","guid":{"rendered":"http:\/\/abhiandroid.com\/ui\/?page_id=1415"},"modified":"2019-06-12T11:10:01","modified_gmt":"2019-06-12T11:10:01","slug":"tabhost","status":"publish","type":"page","link":"https:\/\/abhiandroid.com\/ui\/tabhost","title":{"rendered":"TabHost Tutorial With Example In Android Studio"},"content":{"rendered":"<p>In Android, TabHost is a Container for tabbed window view. This object holds two children one is set of tab labels that the user clicks to select a specific tab and other is a FrameLayout object that displays the content of that page.<\/p>\n<p>Whenever we need to enter or display a lot of information in one activity. A simple and effective method is to use tabs in your interface form which is done using TabHost in Android.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1600\" src=\"\/ui\/wp-content\/uploads\/2016\/04\/TabHost-in-Android.jpg\" alt=\"TabHost in Android\" width=\"543\" height=\"392\" srcset=\"https:\/\/abhiandroid.com\/ui\/wp-content\/uploads\/2016\/04\/TabHost-in-Android.jpg 543w, https:\/\/abhiandroid.com\/ui\/wp-content\/uploads\/2016\/04\/TabHost-in-Android-300x217.jpg 300w\" sizes=\"auto, (max-width: 543px) 100vw, 543px\" \/><\/p>\n<p><span style=\"color: #ff0000;\"><strong>Important\u00a0Note:<\/strong><\/span> A Tabhost holds two children\u2019s from which one is use to set the labels that the users clicks to select tab other is a FrameLayout that is used to display the content of that page. It means when you select any label (or you can say change the tab) the FrameLayout is used to display the content for that particular tab.<\/p>\n<p><span style=\"color: #ff0000;\"><strong>Important\u00a0Note:<\/strong><\/span> For Using TabHost in our MainActivity we need to extend TabActivity instead of Activity.<\/p>\n<hr \/>\n<h4><strong>Basic\u00a0TabHost XML code:<\/strong><\/h4>\n<p>In Below code snippet we shows the TabHost with TabWidget and a FrameLayout.<\/p>\n<pre>&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\r\n&lt;TabHost xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\nandroid:id=\"@android:id\/tabhost\"\r\nandroid:layout_width=\"fill_parent\"\r\nandroid:layout_height=\"fill_parent\"&gt;\r\n\r\n&lt;LinearLayout\r\nandroid:layout_width=\"fill_parent\"\r\nandroid:layout_height=\"fill_parent\"\r\nandroid:orientation=\"vertical\"&gt;\r\n\r\n&lt;FrameLayout\r\nandroid:id=\"@android:id\/tabcontent\"\r\nandroid:layout_width=\"fill_parent\"\r\nandroid:layout_height=\"0dip\"\r\nandroid:layout_weight=\"1\" \/&gt;\r\n\r\n&lt;TabWidget\r\nandroid:id=\"@android:id\/tabs\"\r\nandroid:layout_width=\"fill_parent\"\r\nandroid:layout_height=\"wrap_content\"\r\nandroid:layout_marginBottom=\"-4dp\"\r\nandroid:layout_weight=\"0\" \/&gt;\r\n\r\n&lt;\/LinearLayout&gt;\r\n\r\n&lt;\/TabHost&gt;\r\n<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1601\" src=\"\/ui\/wp-content\/uploads\/2016\/04\/TabHost-UI-in-Android-XML.jpg\" alt=\"TabHost UI in Android XML\" width=\"625\" height=\"450\" srcset=\"https:\/\/abhiandroid.com\/ui\/wp-content\/uploads\/2016\/04\/TabHost-UI-in-Android-XML.jpg 625w, https:\/\/abhiandroid.com\/ui\/wp-content\/uploads\/2016\/04\/TabHost-UI-in-Android-XML-300x216.jpg 300w\" sizes=\"auto, (max-width: 625px) 100vw, 625px\" \/><\/p>\n<hr \/>\n<h4><strong>TabHost.TabSpec:<\/strong><\/h4>\n<p>In Android, A tab has a tab indicator, content, and a tag that is used to keep track of it. This builder helps us to choose among these options. For the tab indicator our choices are set a label or set a label and an icon both together. For the tab content our choices are the id of View, a TabHost.TabContentFactory that creates the view content and an Intent that launches an Activity.<\/p>\n<hr \/>\n<h4><strong>Important Methods Of TabSpec:<\/strong><\/h4>\n<p>Let\u2019s discuss some common methods of a TabSpec which are used to specify the indicator and content for a Tab.<\/p>\n<p><span style=\"color: #008000;\"><strong>1. setIndicator(CharSequence label):<\/strong><\/span> This method is used to set the text to show on tab. In this we specify CharSequence type value to display a label for Tab.<\/p>\n<p>Below we set the \u201cTab 1\u201d as an indicator ( label ) for a tab.<\/p>\n<pre>TabHost tabHost = (TabHost)findViewById(android.R.id.tabhost); \/\/ initiate TabHost\r\nTabHost.TabSpec tabSpec = tabHost.newTabSpec(\"tab1\"); \/\/ Create a new TabSpec using tab host\r\ntabSpec.setIndicator(\"Tab 1\"); \/\/ set the \u201cTab 1\u201d as an indicator for a tab<\/pre>\n<p><span style=\"color: #ff0000;\"><strong>Important Note:<\/strong><\/span>\u00a0Mostly all methods described here needs to be used to make TabHost work. So do refer to the example at the end of\u00a0this article to learn how to use all these method to create TabHost in Android.<\/p>\n<p><span style=\"color: #008000;\"><strong>2. setIndicator(CharSequence label,Drawable icon):<\/strong><\/span> This method is used to Specify a label and icon as the tab indicator. In this method you specify char sequence type value to display a label for tab and drawable to display an icon on tab.<\/p>\n<p>Below we set the \u201cTab 1\u201d as an indicator ( label ) and ic_launcher icon for a tab.<\/p>\n<pre>TabHost tabHost = (TabHost)findViewById(android.R.id.tabhost); \/\/ initiate TabHost\r\nTabHost.TabSpec tabSpec = tabHost.newTabSpec(\"tab1\"); \/\/ Create a new TabSpec using tab host\r\ntabSpec.setIndicator(\"Tab 1\",getResources().getDrawable(R.drawable.ic_launcher)); \/\/ set the label and icon an indicator for a tab\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>3. setContent(Intent intent):<\/strong><\/span> This method is used to specify an intent to use to launch an activity as the tab content. Whenever a user click on this tab an activity is open and display the content.<\/p>\n<p>Below we set an intent that is used to launch an activity as the tab content.<\/p>\n<pre>TabHost tabHost = (TabHost)findViewById(android.R.id.tabhost); \/\/ initiate TabHost\r\nTabHost.TabSpec tabSpec = tabHost.newTabSpec(\"tab1\"); \/\/ Create a new TabSpec using tab host\r\ntabSpec.setIndicator(view); \/\/ set the \u201cTab 1\u201d as an indicator\r\nIntent intent = new Intent(this, MyActivity.class);\r\ntabSpec.setContent(intent); \/\/ specify an intent to use to launch an activity as the tab content\r\n<\/pre>\n<hr \/>\n<h4><strong>Important Methods Of TabHost:<\/strong><\/h4>\n<p>Let\u2019s discuss some important\u00a0methods of a TabHost which are used to configure Tabs in our application.<\/p>\n<p><span style=\"color: #008000;\"><strong>1. addTab(TabSpec\u00a0tabSpec):<\/strong> <\/span>This method is used to add a tab onto a tab widget. Whenever we specify a new tab using TabSpec class we need to add that tab in our TabHost.<\/p>\n<p>Below is an example code with explanation in which we specify a tab using TabSpec class and then add that tab in our tab host using addTab method.<\/p>\n<pre>TabHost tabHost = (TabHost) findViewById(android.R.id.tabhost); \/\/ initiate TabHost\r\nTabHost.TabSpec tabSpec = tabHost.newTabSpec(\"tab1\"); \/\/ Create a new TabSpec using tab host\r\ntabSpec.setIndicator(view); \/\/ set the \u201cTab 1\u201d as an indicator\r\nIntent intent = new Intent(this, MyActivity.class);\r\ntabSpec.setContent(intent); \/\/ specify an intent to use to launch an activity as the tab content\r\ntabHost.addTab(tabSpec); \/\/ add a tab in Tab widget\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>2. clearAllTabs():<\/strong><\/span> This method is used to remove all the tabs from the tab widget associated with TabHost.<\/p>\n<p>Below is an example code in which Firstly we add two tabs and then remove all the tabs from a tab widget.<\/p>\n<pre>TabHost tabHost = (TabHost) findViewById(android.R.id.tabhost); \/\/ initiate TabHost\r\nTabHost.TabSpec tabSpec = tabHost.newTabSpec(\"tab1\"); \/\/ Create a new TabSpec using tab host\r\ntabSpec.setIndicator(\"Tab 1\"); \/\/ set the \u201cTab 1\u201d as an indicator\r\nIntent intent = new Intent(this, MyActivity.class);\r\ntabSpec.setContent(intent);\r\nTabHost.TabSpec tabSpec1 = tabHost.newTabSpec(\"tab2\"); \/\/ Create a new TabSpec using tab host\r\ntabSpec1.setIndicator(\"Tab 2\"); \/\/ set the \u201cTab 2\u201d as an indicator\r\nIntent intent1 = new Intent(this, MyActivity.class);\r\ntabSpec1.setContent(intent1); \/\/ specify an intent to use to launch an activity as the tab content\r\ntabHost.addTab(tabSpec); \/\/ add first tab in Tab widget\r\ntabHost.addTab(tabSpec1); \/\/ add second tab in Tab widget\r\ntabHost.clearAllTabs(); \/\/ clear all the tabs from tab widget\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>3. setCurrentTab(int index):<\/strong><\/span> This method is used to set the current selected tab from the tab widget. By default a tab host set first tab as current tab but we can change it by using this function.<\/p>\n<p>Below is an example code in which firstly we add two tabs and then set the second tab as current tab.<\/p>\n<pre>TabHost tabHost = (TabHost) findViewById(android.R.id.tabhost); \/\/ initiate TabHost\r\nTabHost.TabSpec tabSpec = tabHost.newTabSpec(\"tab1\"); \/\/ Create a new TabSpec using tab host\r\ntabSpec.setIndicator(\"Tab 1\"); \/\/ set the \u201cTab 1\u201d as an indicator\r\nIntent intent = new Intent(this, MyActivity.class);\r\ntabSpec.setContent(intent);\r\nTabHost.TabSpec tabSpec1 = tabHost.newTabSpec(\"tab2\"); \/\/ Create a new TabSpec using tab host\r\ntabSpec1.setIndicator(\"Tab 2\"); \/\/ set the \u201cTab 2\u201d as an indicator\r\nIntent intent1 = new Intent(this, MyActivity.class);\r\ntabSpec1.setContent(intent1); \/\/ specify an intent to use to launch an activity as the tab content\r\ntabHost.addTab(tabSpec); \/\/ add first tab in Tab widget\r\ntabHost.addTab(tabSpec1); \/\/ add second tab in Tab widget\r\ntabHost.setCurrentTab(1); \/\/ set second tab as current selected tab\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>4. setOnTabChangedListener(OnTabChangeListenerl):<\/strong><\/span> This method is used to register a callback to be invoked when the selected state of any of the items in this list changes.<\/p>\n<p>Below we show how to use setOnTabChangedListener in TabHost.<\/p>\n<pre>\/\/ perform set on tab changed listener on tab host\r\ntabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {\r\n@Override\r\npublic void onTabChanged(String tabId) {\r\n\/\/ Add code Here\r\n}\r\n});\r\n<\/pre>\n<hr \/>\n<h4><strong>TabHost Example In Android Studio:<\/strong><\/h4>\n<p>Below is the example of TabHost in which we display a TabHost by using Tab Widget and FrameLayout. In this example we display three tabs named home, contact and about by using TabHost.TabSpec where we display static data. We also implement setOnTabChangeListener, so whenever a tab is changed the name of the tab is displayed by using a Toast.<\/p>\n<p>Below you can download complete Android Studio project code, see final output and read step by step explanation:<\/p>\n<p style=\"text-align: center;\"><a class=\"download\" href=\"https:\/\/github.com\/abhisheksaini4\/TabHostExample\" target=\"_blank\" rel=\"nofollow\">Download Code<\/a><a class=\"help\" title=\"Learn How To Download Code And Import In Android Studio\" href=\"\/androidstudio\/download-code-abhiandroid\" target=\"_blank\" rel=\"nofollow\"> ? <\/a><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1583\" src=\"\/ui\/wp-content\/uploads\/2016\/04\/TabHost-Example-In-Android-Studio.gif\" alt=\"TabHost Example In Android Studio\" width=\"302\" height=\"493\" \/><\/p>\n<p><span style=\"color: #008000;\"><strong>Step 1:<\/strong><\/span><strong>\u00a0<\/strong>Create a new project and name it TabHostExample<\/p>\n<p><span style=\"color: #008000;\"><strong>Step 2:\u00a0<\/strong><\/span>Open res -&gt; layout -&gt;activity_main.xml (or) main.xml and add following code :<\/p>\n<p>In this step we add the code for displaying a TabHost by using TabWidget and Framelayout.<\/p>\n<pre>&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\r\n&lt;TabHost xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\nandroid:id=\"@android:id\/tabhost\"\r\nandroid:layout_width=\"fill_parent\"\r\nandroid:layout_height=\"fill_parent\"&gt;\r\n\r\n\r\n&lt;LinearLayout\r\nandroid:layout_width=\"fill_parent\"\r\nandroid:layout_height=\"fill_parent\"\r\nandroid:orientation=\"vertical\"&gt;\r\n\r\n&lt;FrameLayout\r\nandroid:id=\"@android:id\/tabcontent\"\r\nandroid:layout_width=\"fill_parent\"\r\nandroid:layout_height=\"0dip\"\r\nandroid:layout_weight=\"1\" \/&gt;\r\n\r\n&lt;TabWidget\r\nandroid:id=\"@android:id\/tabs\"\r\nandroid:layout_width=\"fill_parent\"\r\nandroid:layout_height=\"wrap_content\"\r\nandroid:layout_marginBottom=\"-4dp\"\r\nandroid:layout_weight=\"0\" \/&gt;\r\n\r\n&lt;\/LinearLayout&gt;\r\n\r\n&lt;\/TabHost&gt;\r\n<\/pre>\n<p><strong><span style=\"color: #008000;\">Step 3:<\/span>\u00a0<\/strong>Open src -&gt; package -&gt; MainActivity.java<\/p>\n<p>In this step we add the code to\u00a0initiate the TabHost and then add three tabs home, contact and about by using TabHost.TabSpec where we display static data. We also implement setOnTabChangeListener so whenever a tab is changed the name of the tab is displayed by using a Toast.<\/p>\n<p>For Using TabHost in our MainActivity we need to extend TabActivity instead of Activity.<\/p>\n<pre>package example.abhiandroid.tabhostexample;\r\n\r\nimport android.app.TabActivity;\r\nimport android.content.Intent;\r\nimport android.os.Bundle;\r\nimport android.view.Menu;\r\nimport android.view.MenuItem;\r\nimport android.widget.TabHost;\r\nimport android.widget.Toast;\r\n\r\npublic class MainActivity extends TabActivity {\r\n    \/**\r\n     * Called when the activity is first created.\r\n     *\/\r\n    @Override\r\n    public void onCreate(Bundle savedInstanceState) {\r\n        super.onCreate(savedInstanceState);\r\n        setContentView(R.layout.activity_main);\r\n\r\n        TabHost tabHost = (TabHost) findViewById(android.R.id.tabhost); \/\/ initiate TabHost\r\n        TabHost.TabSpec spec; \/\/ Reusable TabSpec for each tab\r\n        Intent intent; \/\/ Reusable Intent for each tab\r\n\r\n        spec = tabHost.newTabSpec(\"home\"); \/\/ Create a new TabSpec using tab host\r\n        spec.setIndicator(\"HOME\"); \/\/ set the \u201cHOME\u201d as an indicator\r\n        \/\/ Create an Intent to launch an Activity for the tab (to be reused)\r\n        intent = new Intent(this, HomeActivity.class);\r\n        spec.setContent(intent);\r\n        tabHost.addTab(spec);\r\n\r\n        \/\/ Do the same for the other tabs\r\n\r\n        spec = tabHost.newTabSpec(\"Contact\"); \/\/ Create a new TabSpec using tab host\r\n        spec.setIndicator(\"CONTACT\"); \/\/ set the \u201cCONTACT\u201d as an indicator\r\n        \/\/ Create an Intent to launch an Activity for the tab (to be reused)\r\n        intent = new Intent(this, ContactActivity.class);\r\n        spec.setContent(intent);\r\n        tabHost.addTab(spec);\r\n\r\n        spec = tabHost.newTabSpec(\"About\"); \/\/ Create a new TabSpec using tab host\r\n        spec.setIndicator(\"ABOUT\"); \/\/ set the \u201cABOUT\u201d as an indicator\r\n        \/\/ Create an Intent to launch an Activity for the tab (to be reused)\r\n        intent = new Intent(this, AboutActivity.class);\r\n        spec.setContent(intent);\r\n        tabHost.addTab(spec);\r\n        \/\/set tab which one you want to open first time 0 or 1 or 2\r\n        tabHost.setCurrentTab(1);\r\n        tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {\r\n            @Override\r\n            public void onTabChanged(String tabId) {\r\n                \/\/ display the name of the tab whenever a tab is changed\r\n                Toast.makeText(getApplicationContext(), tabId, Toast.LENGTH_SHORT).show();\r\n            }\r\n        });\r\n\r\n\r\n    }\r\n\r\n    \r\n}<\/pre>\n<p><strong><span style=\"color: #008000;\">Step 4:<\/span>\u00a0<\/strong>Now we need 3 activities and 3 xml layouts for three tabs. So create three activities by right click on your package folder and create classes and name them as HomeActivity, ContactActivity and AboutActivity and add the following code respectively.<\/p>\n<p><strong>Right Click on package folder -&gt; New -&gt; Class and create:<\/strong><\/p>\n<p><strong>HomeActivity.class<\/strong><\/p>\n<pre>package example.abhiandroid.tabhostexample;\r\n\r\nimport android.support.v7.app.AppCompatActivity;\r\nimport android.os.Bundle;\r\n\r\npublic class HomeActivity extends AppCompatActivity {\r\n\r\n    @Override\r\n    protected void onCreate(Bundle savedInstanceState) {\r\n        super.onCreate(savedInstanceState);\r\n        setContentView(R.layout.activity_home);\r\n    }\r\n}<\/pre>\n<p><strong>ContactActivity.class<\/strong><\/p>\n<pre>package example.abhiandroid.tabhostexample;\r\n\r\nimport android.support.v7.app.AppCompatActivity;\r\nimport android.os.Bundle;\r\n\r\npublic class ContactActivity extends AppCompatActivity {\r\n\r\n    @Override\r\n    protected void onCreate(Bundle savedInstanceState) {\r\n        super.onCreate(savedInstanceState);\r\n        setContentView(R.layout.activity_contact);\r\n    }\r\n}<\/pre>\n<p><strong>AboutActivity.class<\/strong><\/p>\n<pre>package example.abhiandroid.tabhostexample;\r\n\r\nimport android.support.v7.app.AppCompatActivity;\r\nimport android.os.Bundle;\r\n\r\npublic class AboutActivity extends AppCompatActivity {\r\n\r\n    @Override\r\n    protected void onCreate(Bundle savedInstanceState) {\r\n        super.onCreate(savedInstanceState);\r\n        setContentView(R.layout.activity_about);\r\n    }\r\n}<\/pre>\n<p><strong><span style=\"color: #008000;\">Step 5:<\/span> <\/strong>\u00a0Now create 3 xml layouts by\u00a0<strong>right clicking on res\/layout -&gt; New -&gt; Layout Resource\u00a0<\/strong><strong>File<\/strong> and name them as activity_home, activity_contact and activity_about and add the following code in respective files.<\/p>\n<p>Here we will design the basic simple UI for all the three tabs.<\/p>\n<p><strong>activity_home.xml code:<\/strong><\/p>\n<pre>&lt;RelativeLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\nxmlns:tools=\"http:\/\/schemas.android.com\/tools\"\r\nandroid:layout_width=\"match_parent\"\r\nandroid:layout_height=\"match_parent\"\r\nandroid:paddingBottom=\"@dimen\/activity_vertical_margin\"\r\nandroid:paddingLeft=\"@dimen\/activity_horizontal_margin\"\r\nandroid:paddingRight=\"@dimen\/activity_horizontal_margin\"\r\nandroid:paddingTop=\"@dimen\/activity_vertical_margin\"\r\ntools:context=\"example.abhiandroid.tabhostexample.HomeActivity\"&gt;\r\n\r\n&lt;TextView\r\nandroid:layout_width=\"wrap_content\"\r\nandroid:layout_height=\"wrap_content\"\r\nandroid:layout_centerInParent=\"true\"\r\nandroid:textSize=\"25sp\"\r\nandroid:textColor=\"#f00\"\r\nandroid:textStyle=\"bold\"\r\nandroid:text=\"Home Activity\" \/&gt;\r\n\r\n&lt;\/RelativeLayout&gt;\r\n<\/pre>\n<p><strong>activity_contact.xml:<\/strong><\/p>\n<pre>&lt;RelativeLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\nxmlns:tools=\"http:\/\/schemas.android.com\/tools\"\r\nandroid:layout_width=\"match_parent\"\r\nandroid:layout_height=\"match_parent\"\r\nandroid:paddingBottom=\"@dimen\/activity_vertical_margin\"\r\nandroid:paddingLeft=\"@dimen\/activity_horizontal_margin\"\r\nandroid:paddingRight=\"@dimen\/activity_horizontal_margin\"\r\nandroid:paddingTop=\"@dimen\/activity_vertical_margin\"\r\ntools:context=\"example.abhiandroid.tabhostexample.ContactActivity\"&gt;\r\n\r\n&lt;TextView\r\nandroid:layout_width=\"wrap_content\"\r\nandroid:layout_height=\"wrap_content\"\r\nandroid:layout_centerInParent=\"true\"\r\nandroid:text=\"Contact Activity\"\r\nandroid:textColor=\"#00f\"\r\nandroid:textSize=\"25sp\"\r\nandroid:textStyle=\"bold\" \/&gt;\r\n\r\n&lt;\/RelativeLayout&gt;\r\n<\/pre>\n<p><strong>activity_about.xml:<\/strong><\/p>\n<pre>&lt;RelativeLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\nxmlns:tools=\"http:\/\/schemas.android.com\/tools\"\r\nandroid:layout_width=\"match_parent\"\r\nandroid:layout_height=\"match_parent\"\r\nandroid:paddingBottom=\"@dimen\/activity_vertical_margin\"\r\nandroid:paddingLeft=\"@dimen\/activity_horizontal_margin\"\r\nandroid:paddingRight=\"@dimen\/activity_horizontal_margin\"\r\nandroid:paddingTop=\"@dimen\/activity_vertical_margin\"\r\ntools:context=\"example.abhiandroid.tabhostexample.AboutActivity\"&gt;\r\n\r\n&lt;TextView\r\nandroid:layout_width=\"wrap_content\"\r\nandroid:layout_height=\"wrap_content\"\r\nandroid:layout_centerInParent=\"true\"\r\nandroid:textSize=\"25sp\"\r\nandroid:textColor=\"#0f0\"\r\nandroid:textStyle=\"bold\"\r\nandroid:text=\"About Activity\" \/&gt;\r\n&lt;\/RelativeLayout&gt;\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>Step 6:<\/strong><\/span> Open\u00a0<strong>AndroidManifest.xml<\/strong><\/p>\n<p>In this step we open\u00a0Manifest file\u00a0and\u00a0add the code for defining Home, Contact and About activity.<\/p>\n<pre>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;manifest xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\npackage=\"example.abhiandroid.tabhostexample\"&gt;\r\n\r\n&lt;application\r\nandroid:allowBackup=\"true\"\r\nandroid:icon=\"@mipmap\/ic_launcher\"\r\nandroid:label=\"@string\/app_name\"\r\nandroid:theme=\"@style\/AppTheme\"&gt;\r\n&lt;activity\r\nandroid:name=\".MainActivity\"\r\nandroid:label=\"@string\/app_name\"&gt;\r\n&lt;intent-filter&gt;\r\n&lt;action android:name=\"android.intent.action.MAIN\" \/&gt;\r\n\r\n&lt;category android:name=\"android.intent.category.LAUNCHER\" \/&gt;\r\n&lt;\/intent-filter&gt;\r\n&lt;\/activity&gt;\r\n&lt;activity\r\nandroid:name=\".HomeActivity\"\r\nandroid:label=\"@string\/title_activity_my\"&gt;&lt;\/activity&gt;\r\n&lt;activity\r\nandroid:name=\".AboutActivity\"\r\nandroid:label=\"@string\/title_activity_about\"&gt;&lt;\/activity&gt;\r\n&lt;activity\r\nandroid:name=\".ContactActivity\"\r\nandroid:label=\"@string\/title_activity_contact\"&gt;&lt;\/activity&gt;\r\n&lt;\/application&gt;\r\n\r\n&lt;\/manifest&gt;\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>Step 7:<\/strong><\/span> Open <strong>Strings.xml<\/strong><\/p>\n<p>Now go to app-&gt; values -&gt; strings.xml and add the below codes. Here we are defining the String that we used in the earlier step.<\/p>\n<pre>&lt;resources&gt;\r\n    &lt;string name=\"app_name\"&gt;TabHostExample&lt;\/string&gt;\r\n    &lt;string name=\"hello_world\"&gt;Hello world!&lt;\/string&gt;\r\n    &lt;string name=\"action_settings\"&gt;Settings&lt;\/string&gt;\r\n    &lt;string name=\"title_activity_my\"&gt;MyActivity&lt;\/string&gt;\r\n    &lt;string name=\"title_activity_about\"&gt;AboutActivity&lt;\/string&gt;\r\n    &lt;string name=\"title_activity_contact\"&gt;ContactActivity&lt;\/string&gt;\r\n&lt;\/resources&gt;<\/pre>\n<p><span style=\"color: #008000;\"><strong>Output:<\/strong><\/span><\/p>\n<p>Now run the App and you will see 3 tabs in the bottom which we created in TabHost. Now click on any Tab and activity corresponding to it will be open.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In Android, TabHost is a Container for tabbed window view. This object holds two children one is set of tab labels that the user clicks to select a specific tab and other is a FrameLayout object that displays the content of that page. Whenever we need to enter or display a lot of information in &hellip; <a href=\"https:\/\/abhiandroid.com\/ui\/tabhost\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">TabHost Tutorial With Example In Android Studio<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"open","ping_status":"closed","template":"home.php","meta":{"_acf_changed":false,"footnotes":""},"class_list":["post-1415","page","type-page","status-publish","hentry"],"acf":[],"psp_head":"<title>TabHost Tutorial With Example In Android Studio \u2013 Abhi Android<\/title>\r\n<meta name=\"description\" content=\"Complete step by step TabHost tutorial with its UI designing, methods explanation including TabSpec with example in Android Studio. In Android, TabHost is a Container for tabbed window view.\" \/>\r\n<meta name=\"robots\" content=\"index,follow\" \/>\r\n<link rel=\"canonical\" href=\"https:\/\/abhiandroid.com\/ui\/tabhost\" \/>\r\n","_links":{"self":[{"href":"https:\/\/abhiandroid.com\/ui\/wp-json\/wp\/v2\/pages\/1415","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/abhiandroid.com\/ui\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/abhiandroid.com\/ui\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/abhiandroid.com\/ui\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/abhiandroid.com\/ui\/wp-json\/wp\/v2\/comments?post=1415"}],"version-history":[{"count":3,"href":"https:\/\/abhiandroid.com\/ui\/wp-json\/wp\/v2\/pages\/1415\/revisions"}],"predecessor-version":[{"id":2800,"href":"https:\/\/abhiandroid.com\/ui\/wp-json\/wp\/v2\/pages\/1415\/revisions\/2800"}],"wp:attachment":[{"href":"https:\/\/abhiandroid.com\/ui\/wp-json\/wp\/v2\/media?parent=1415"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}