11 TabBar

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

TabHost

Project : TabBarDemo

TabHost TextView Tab Tab

Clock

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


<TabHost
android:id="@+id/tabHost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</TabWidget>

<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<LinearLayout


android:id = "@+id/tab1"

android:layout_width = "fill_parent"

android:layout_height = "fill_parent"

android:orientation = "vertical"

android:gravity = "center" >

<TextView


android:layout_width = "wrap_content"


android:layout_height = "wrap_content"


android:text = "This is Tab1"


android:textSize = "18pt" >

</TextView>
</LinearLayout>
<LinearLayout


android:id = "@+id/tab2"

android:layout_width = "fill_parent"

android:layout_height = "fill_parent"

android:orientation = "vertical"

android:gravity = "center" >

<AnalogClock


android:layout_width = "wrap_content"


android:layout_height = "wrap_content" >

</AnalogClock>
</LinearLayout>
</FrameLayout>
</TabHost>

<TabHost
android:id="@+id/tabHost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android" >

Code XML Layout TabHost


id : TabHost

width : parent

height : parent

<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</TabWidget>

Code XML Layout TabWidget


id : tabs

width : Parent TabHost

height : TabBar

<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

Code XML Layout ListView


id : tabcontent

width : Parent TabHost

height : Parent TabHost

<LinearLayout


android:id = "@+id/tab1"

android:layout_width = "fill_parent"

android:layout_height = "fill_parent"

android:orientation = "vertical"

android:gravity = "center" >

<TextView


android:layout_width = "wrap_content"


android:layout_height = "wrap_content"


android:text = "This is Tab1"


android:textSize = "18pt" >

</TextView>
</LinearLayout>

Code XML Layout LinearLayout TextView


id : tab1

width : Parent FrameLayout

height : Parent FrameLayout

orientation : vertical

gravity : center

<LinearLayout


android:id = "@+id/tab2"

android:layout_width = "fill_parent"

android:layout_height = "fill_parent"

android:orientation = "vertical"

android:gravity = "center" >

<AnalogClock


android:layout_width = "wrap_content"


android:layout_height = "wrap_content" >

</AnalogClock>
</LinearLayout>

Code XML Layout LinearLayout TextView


id : tab2

width : Parent FrameLayout

height : Parent FrameLayout

orientation : vertical

gravity : center

import android.app.Activity;
import android.os.Bundle;
import android.widget.TabHost;
public class TabBarDemo extends Activity {


TabHost tabBar;

TabHost.TabSpec spec;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tabBar = (TabHost)findViewById(R.id.tabHost);
tabBar.setup();

spec = tabBar.newTabSpec("Tab1");

spec.setContent(R.id.tab1);

spec.setIndicator("Tab1");
tabBar.addTab(spec);

spec = tabBar.newTabSpec("Tab2");

spec.setContent(R.id.tab2);

spec.setIndicator("Clock");
tabBar.addTab(spec);
}
}

TabHost tabBar;
TabHost.TabSpec spec;

Code Java TabHost TabSpace

tabBar = (TabHost)findViewById(R.id.tabHost);
tabBar.setup();

Code Java TabHost Layout ( XML )

Tab

1. TabSpace newTabSpace TabHost

spec = tabBar.newTabSpec("Tab1");

2. Tab id Tab
LinearLayout id tab1

spec.setContent(R.id.tab1);

3. Tab User setIndicator

spec.setIndicator("Tab1");

4. Add TabSpace TabHost AddTab

tabBar.addTab(spec);

Tab 2 Tab 1

spec = tabBar.newTabSpec("Tab2");

spec.setContent(R.id.tab2);

spec.setIndicator("Clock");
tabBar.addTab(spec);

drbomkung@gmail.com

You might also like