Tabs (tabhost) conveniently set multiple tabs on a window, each of which is equivalent to getting a component with the same size as an external container
In this way, multiple components can be placed in a container.
Create 4 Java files and correspond to layout
Create master Java, code
1 Package Lianxi;2 3 import Com.example.jichu_lianxi. R;4 5 import android.app.TabActivity;6 import android.content.Intent;7 import android.content.res.Resources;8 import Android.os.Bundle;9 import Android.widget.TabHost;Ten One Public classTobhost_lianxi extends tabactivity{ A @Override - protected voidonCreate (Bundle savedinstancestate) { - //TODO auto-generated Method Stub the super.oncreate (savedinstancestate); - - //gets the current Activity label, the implementation of the method has been implemented Setcontentview (com.android.internal.r.layout.tab_content); -Resources Resources =getresources (); +Tabhost Tabhost =gettabhost (); - Tabhost.tabspec spec; + /* A * Explanation of the method: at * 1. Newtabspec ("artist") creates a label entry, where artist is its label identifier - * 2. Setindicator ("Label 1", Resources.getdrawable (R.drawable.bulb_off)) - * Display the text and the icon on the label (the icon is not a picture, but an XML file) - */ - //Add first label -Intent Intent =NewIntent (Tobhost_lianxi. This, Keyonclick.class); inSpec = Tabhost.newtabspec ("Keyonclick"). Setindicator ("Label 1", Resources.getdrawable (R.drawable.bulb_off)). SetContent (intent); -Tabhost.addtab (spec);//add a label to a label item to //Add a second label +Intent Intent2 =NewIntent (Tobhost_lianxi. This, List_lianxi.class); -Spec = Tabhost.newtabspec ("List"). Setindicator ("Label 2", Resources.getdrawable (R.drawable.bulb_off)). SetContent (Intent2); the Tabhost.addtab (spec); * //Add a third label $Intent Intent3 =NewIntent (Tobhost_lianxi. This, Togglebutton_lianxi.class);Panax NotoginsengSpec = Tabhost.newtabspec ("ToggleButton"). Setindicator ("Label 3", Resources.getdrawable (R.drawable.bulb_off)). SetContent (INTENT3); - Tabhost.addtab (spec); the //Add a fourth label +Intent intent4 =NewIntent (Tobhost_lianxi. This, Togglebutton_lianxi.class); ASpec = Tabhost.newtabspec ("Toggle"). Setindicator ("Label 4", Resources.getdrawable (R.drawable.bulb_off)). SetContent (INTENT4); the Tabhost.addtab (spec); + - //Sets the default display label that is opened for the first time, with parameters matching the parameters of the. Newtabspec $ //Tabhost.setcurrenttabbytag ("toggle"); $ //Sets the default displayed label to be opened for the first time, and the parameter represents the order in which it is added to the label, starting at 0 -Tabhost.setcurrenttab (1); - the } - Wuyi}Main code
Where the Keyonclick.java List_lianxi.java Togglebutton_lianxi.java code is not affixed
Don't forget to modify the code in the Androidmanifest.xml file
<Application Android:allowbackup="true"Android:icon="@drawable/ic_launcher"Android:label="@string/app_name"Android:theme="@style/apptheme"> <activity android:name="Lianxi. Mainactivity"> <intent-Filter> <action android:name="Android.intent.action.MAIN"/> <category android:name="Android.intent.category.LAUNCHER"/> </intent-filter> </activity> <activity android:name="Lianxi. Newactivity"></activity> <activity android:name="Lianxi. Alertdialog_lianxi"></activity> <activity android:name="Lianxi. Notification_lianxi"></activity> <activity android:name="Lianxi. Keyonclick"></activity> <activity android:name="Lianxi. List_lianxi"></activity> <activity android:name="Lianxi. Togglebutton_lianxi"></activity> <activity android:name="Lianxi. Tobhost_lianxi"></activity> </application>
(The first one is label 2.) Because Tabhost.setcurrenttab (1); Set 2nd added tab item to default display, starting from 0)
About the implementation of the Android Development tab