TabHost in Android

 // TabHost App


// MainActivity.java **************************************

package com.higoigfuggiu.itifuffi;

 

import android.app.Activity;

import android.os.Bundle;

import android.widget.TabHost;


public class MainActivity extends Activity { 


    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

TabHost th=findViewById(R.id.host);

th.setup();

TabHost.TabSpec spec= th.newTabSpec("One");

spec.setContent(R.id.tab1);

spec.setIndicator("Home");

th.addTab(spec);

spec= th.newTabSpec("Two");

spec.setContent(R.id.tab2);

spec.setIndicator("Favorite");

th.addTab(spec);

spec= th.newTabSpec("Three");

spec.setContent(R.id.tab3);

spec.setIndicator("Famous");

th.addTab(spec);

spec= th.newTabSpec("Four");

spec.setContent(R.id.tab4);

spec.setIndicator("History");

th.addTab(spec);

    }

}





// main.xml ***********************************************************


<?xml version="1.0" encoding="utf-8"?>

<LinearLayout

xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent">


<TabHost

android:layout_width="match_parent"

android:layout_height="match_parent"

android:id="@+id/host">


<LinearLayout

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical">


<TabWidget

android:id="@android:id/tabs"

android:layout_width="match_parent"

android:layout_height="wrap_content"/>


<FrameLayout

android:id="@android:id/tabcontent"

android:layout_width="match_parent"

android:layout_height="match_parent">


<LinearLayout

android:id="@+id/tab1"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"

android:background="#FF99EEFB">


<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Hello Tab 1"/>


</LinearLayout>


<LinearLayout

android:id="@+id/tab2"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"

android:background="#FF5668FF">


<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Hello Tab 2"/>


</LinearLayout>


<LinearLayout

android:id="@+id/tab3"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"

android:background="#FFFF7EC7">


<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Hello Tab 3"/>


</LinearLayout>

<LinearLayout

android:id="@+id/tab4"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"

android:background="#00ff00">


<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Hello Tab 4"/>


</LinearLayout>


</FrameLayout>


</LinearLayout>


</TabHost>


</LinearLayout>