Tabhost Introduction
Although the official proposal is to replace tabhost with Fagment, we would like to introduce. Tabhost is a very simple component, tabhost can be conveniently placed in the window multiple tabs, each tab equivalent to get a placement.
Attention
The interior of the tabhost requires two components, one of which is tabwidget and framelayout two components.
Call History Interface
<?xml version= "1.0" encoding= "Utf-8"?><tabhost xmlns:android = "http://schemas.android.com/apk/res/android" xmlns:tools = "Http://schemas.android.com/tools" android:layout_width = "match_parent" android:layout_height = "match_parent" android:layout_weight = "1" android:id = "@android: Id/tabhost" > <linearlayoutandroid:layout_width="Wrap_content"android:layout_height ="Wrap_content"android:orientation="vertical"> <tabwidgetandroid:layout_width="Match_parent"android:layout_height ="Wrap_content"android:id="@android: Id/tabs"/> <framelayoutandroid:layout_width="Match_parent"android:layout_height ="Match_parent"android:id="@android: Id/tabcontent"> <linearlayoutandroid:layout_width="Fill_parent"android:layout_ Height="Fill_parent"android:orientation="vertical"android:id ="@+id/tab01"> <TextViewandroid:layout_width="Match_parent"android:layout_height= "Wrap_content" Android:text="Hello"/> <TextViewandroid:layout_width="Match_parent"android:layout_height ="Wrap_content"android:text="Hello"/> </linearlayout> <linearlayoutandroid:layout_width="Fill_parent"android:layout_height ="Fill_parent"android:orientation="vertical"android:id="@+id/ TAB02 "> <TextViewandroid:layout_width="Match_parent"android:layout_ Height="Wrap_content"android:text="Hello"/> <TextViewandroid:layout_width="Match_parent"android:layout_height= "Wrap_content" Android:text="Hello"/> </linearlayout> <linearlayoutandroid:layout_width="Fill_parent"android:layout_height ="Fill_parent"android:orientation="vertical"android:id="@+id/ Tab03 "> <TextViewandroid:layout_width="Match_parent"android:layout_ Height="Wrap_content"android:text="Hello"/> <TextViewandroid:layout_width="Match_parent"android:layout_height= "Wrap_content" Android:text="Hello"/> </linearlayout> </framelayout> </linearlayout></tabhost>
Package Peng. Liu. Test;Import Android. App. Tabactivity;Import Android. OS. Bundle;Import Android. Widgets. Tabhost;public class Mainactivity extends tabactivity {@Override protected void onCreate (Bundle savedinstancestate) { Super. OnCreate(savedinstancestate);Setcontentview (R. Layout. Activity_main);Tabhost tabhost = Gettabhost ();Tabhost. TabspecTabspec = Tabhost. Newtabspec("TAB01"). Setindicator("answered phone"). SetContent(R. ID. Tab01);Tabhost. AddTab(TABSPEC);Tabhost. TabspecTABSPEC1 = Tabhost. Newtabspec("TAB02"). Setindicator("Call phone"). SetContent(R. ID. Tab12H;Tabhost. TabspecTABSPEC2 = Tabhost. Newtabspec("TAB03"). Setindicator("Missed Call"). SetContent(R. ID. Tab03);Tabhost. AddTab(TABSPEC1);Tabhost. AddTab(TABSPEC2);}}
Android Tabhost Components-android learning Journey (40)