Main Code : TabHostExample.java
package
com.example;
import
android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
import android.widget.TextView;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
import android.widget.TextView;
public
class TabHostExample extends Activity
{
/** Called when the activity is first created. */
TabHost tabHost;
@Override
public void onCreate(Bundle savedInstanceState)
{
/** Called when the activity is first created. */
TabHost tabHost;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tabHost=(TabHost)findViewById(R.id.tabHost);
tabHost.setup();
TabSpec spec1=tabHost.newTabSpec("TAB 1");
spec1.setContent(R.id.tab1);
spec1.setIndicator("TAB 1");
TabSpec spec2=tabHost.newTabSpec("TAB 2");
spec2.setIndicator("TAB 2");
spec2.setContent(R.id.tab2);
TabSpec spec3=tabHost.newTabSpec("TAB 3");
spec3.setContent(R.id.tab3);
spec3.setIndicator("TAB 3");
tabHost.addTab(spec1);
tabHost.addTab(spec2);
tabHost.addTab(spec3);
}
}
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tabHost=(TabHost)findViewById(R.id.tabHost);
tabHost.setup();
TabSpec spec1=tabHost.newTabSpec("TAB 1");
spec1.setContent(R.id.tab1);
spec1.setIndicator("TAB 1");
TabSpec spec2=tabHost.newTabSpec("TAB 2");
spec2.setIndicator("TAB 2");
spec2.setContent(R.id.tab2);
TabSpec spec3=tabHost.newTabSpec("TAB 3");
spec3.setContent(R.id.tab3);
spec3.setIndicator("TAB 3");
tabHost.addTab(spec1);
tabHost.addTab(spec2);
tabHost.addTab(spec3);
}
}
Layout Code : main.xml
<?xml version="1.0"
encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<AbsoluteLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.78" >
<TabHost
android:id="@+id/tabHost"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_x="0dp"
android:layout_y="0dp" >
<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"
>
</TabWidget>
<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:contentDescription="HOME" >
<TextView
android:id="@+id/textView1"
android:layout_width="204dp"
android:layout_height="match_parent"
android:paddingLeft="10dp"
android:text="TAB 1"/>
</LinearLayout>
<LinearLayout
android:id="@+id/tab2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="HOME" >
<TextView
android:id="@+id/textView2"
android:layout_width="204dp"
android:layout_height="match_parent"
android:paddingLeft="10dp"
android:text="TAB 2"/>
</LinearLayout>
<LinearLayout
android:id="@+id/tab3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="HOME" >
<TextView
android:id="@+id/textView3"
android:layout_width="204dp"
android:layout_height="match_parent"
android:paddingLeft="10dp"
android:text="TAB 3"/>
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
</AbsoluteLayout>
No comments:
Post a Comment