1.TAB ACTIVITY ,
2.TAB LAYOUT,
3.TABHOST WITH ACTIVITY.
In this blog implement tabhost with activity in TabWidget.
Step 1.
create a android project in your plateform inside workspace.
Step 2
create MainActivity,java inside src folder..
MainActivity,java
.........................................................................................................................................................
package com.example.androidbeginnerpoin;
import android.support.v7.app.ActionBarActivity;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TabHost;
public class MainActivity extends TabActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Resources res = getResources();
TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
Intent intent;
intent = new Intent().setClass(this, CallActivity.class);
spec = tabHost.newTabSpec("Call")
.setIndicator("Call", res.getDrawable(R.drawable.button_action))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, MessageActivity.class);
spec = tabHost.newTabSpec("Message")
.setIndicator("Message", res.getDrawable(R.drawable.button_action))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, ContactActivity.class);
spec = tabHost
.newTabSpec("Contact")
.setIndicator("Contact", res.getDrawable(R.drawable.button_action))
.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(0);
}
}
Step 3.
create activity_main.xml inside res folder....
in this class dropdwon TabWidget.
............................................................................................................................................................
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"/>
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:layout_marginBottom="-4dp"/>
</LinearLayout>
</TabHost>
Step 4.
you can create three Activity insede res folder
CallActivity .java.
..............................................................................................................................................................
package com.example.androidbeginnerpoin;
import android.app.Activity;
import android.os.Bundle;
public class CallActivity extends Activity{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.call_activity);
}
}
ContactActivity.java.
.............................................................................................................................................................
package com.example.androidbeginnerpoin;
import android.app.Activity;
import android.os.Bundle;
public class ContactActivity extends Activity{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.contact);
}
}
MessageActivity .java
...........................................................................................................................................................
package com.example.androidbeginnerpoin;
import android.app.Activity;
import android.os.Bundle;
public class MessageActivity extends Activity{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.message);
}
}
Step5.
create three xml class inside res folder.
call_activity.xml.
..............................................................................................................................................................
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#b5f2bc">
<ImageView
android:id="@+id/imageView1"
android:layout_width="300dp"
android:layout_height="100dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="141dp"
android:src="@drawable/poin_logo" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/imageView1"
android:layout_centerHorizontal="true"
android:layout_marginTop="61dp"
android:text="CALL TAB"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
contact.xml.
..................................................................................................................................................................
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#9ccee9">
<ImageView
android:id="@+id/imageView1"
android:layout_width="300dp"
android:layout_height="100dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="141dp"
android:src="@drawable/poin_logo" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/imageView1"
android:layout_centerHorizontal="true"
android:layout_marginTop="61dp"
android:text="CONTACT TAB"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
message.xml.
...................................................................................................................................................................
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#e3e560">
<ImageView
android:id="@+id/imageView1"
android:layout_width="300dp"
android:layout_height="100dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="141dp"
android:src="@drawable/poin_logo" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/imageView1"
android:layout_centerHorizontal="true"
android:layout_marginTop="61dp"
android:text="MESSAGE TAB"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
try this code, i hope my blog help you.