tags:

views:

76

answers:

1

Respected All I have to add TabBar in my application, but i don't know how to add tab bar to application or activity. Can you help me for that.

Thank You Vikram Kadam

+1  A: 

You have to use a TabHost. You can find a clear example here. Read the tuto for the explanations, here below you have just the code. In short :
you need an xml file with some layout for each tab, and an activity to display the tabs : In your xml tabs.xml :

<TabHost
id=”@+id/tabs”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
>

<TabWidget
id=”@android:id/tabs”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
/>
<FrameLayout
id=”@android:id/tabcontent”
android:layout_width=”fill_parent”
android:layout_height=”200px”
android:paddingTop=”30px”
>
<LinearLayout
id=”@+id/content1″
android:orientation=”vertical”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
android:background=”#ff99ccff”
>
<TextView
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:text=”tab item uno :) ”
/>
</LinearLayout>
<LinearLayout
id=”@+id/content2″
android:orientation=”vertical”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
android:background=”#ffffcc99″
>
<TextView
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:text=”tab item dos :/”
/>
<Button
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:text=”tabhost needs”
/>
<Button
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:text=”to be upgraded ;) ”
/>
</LinearLayout>
</FrameLayout>
</TabHost>
</LinearLayout>

In the onCreate method of your activity :

setContentView(R.layout.tabs);

TabHost tabs = (TabHost)this.findViewById(R.id.tabs);
tabs.setup();

tabs.addTab(“one”, R.id.content1, “labelone”);
tabs.addTab(“two”, R.id.content2, “labeltwo”);

Thanks Jeff for the tuto

Sephy
Thank You Sephy I will implement it in my code.
Vikram
Sephy can we align that tab bar to bottom of screen.
Vikram
Well, I don't know ... I'm used to using this with the default display. I think you need to override TabHost/TabWidget and change the bevahiour. That might be quite long...
Sephy