Sometimes people use tabhost+ other implementations of the demo. How to use tabhost simply?
Let's look at the example below:
public class Mainactivity extends tabactivity {public tabhost tabhost; @Overrideprotected void OnCreate (Bundle Savedinstancestate) {super.oncreate (savedinstancestate);//Get Object tabhost = Gettabhost (); Tabhost.addtab ( Tabhost.newtabspec ("index"). Setindicator ("Real-time News"). SetContent (New Intent (this, indexactivity.class))); Tabhost.addtab (Tabhost.newtabspec ("center"). Setindicator ("My Space"). SetContent (New Intent (This, Middleactivity.class)); Tabhost.addtab (Tabhost.newtabspec ("Self"). Setindicator ("Settings"). SetContent (New Intent (this , Lastactivity.class)));//The current tab//specified by index specifies the index starting from 0//which page to display at the beginning Tabhost.setcurrenttab (0); Zero-based} @Overridepublic boolean Oncreateoptionsmenu (Menu menu) {//Inflate the menu; This adds items to the action Bar if It is Present.getmenuinflater (). Inflate (R.menu.main, menu); return true;}}
Two
(2) Tabhost tab at the bottom of the example
With the LinearLayout layout, you can set the weight property to place the tab at the bottom
1. XML layout file
<?xml version= "1.0" encoding= "Utf-8"? ><tabhost xmlns:android= "Http://schemas.android.com/apk/res/android "Android:id=" @+id/tabhost "android:layout_width=" fill_parent "android:layout_height=" Fill_parent "Android:bac Kground= "@android: Color/white" android:orientation= "vertical" > <linearlayout android:layout_width= "Mat Ch_parent "android:layout_height=" match_parent "android:orientation=" vertical "> <framelayout Android:id= "@android: Id/tabcontent" android:layout_width= "Fill_parent" Android:layout_heig ht= "0dip" android:layout_weight= "1.0" > </FrameLayout> <tabwidget android: Id= "@android: Id/tabs" android:layout_width= "match_parent" android:layout_height= "Wrap_content" > </TabWidget> </LinearLayout></TabHost>
2, Mainactivity
public class Mainactivity extends activitygroup{private tabhost mtabhost; @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); Inittabs (); } private void Inittabs () {mtabhost = (tabhost) Findviewbyid (r.id.tabhost); Mtabhost.setup (This.getlocalactivitymanager ()); Intent Intent = new Intent (this, homepageactivity.class); Mtabhost.addtab (Mtabhost.newtabspec ("Tab1"). Setindicator (GetString (r.string.homepage_indicator), Getresour CES (). getdrawable (R.drawable.homepage_indicator_selector)). SetContent (intent)); Intent = new Intent (this, billboardactivity.class); Mtabhost.addtab (Mtabhost.newtabspec ("Tab2"). Setindicator (GetString (r.string.billboard_indicator), Getresou RCEs (). getdrawable (R.drawable.billboard_indicator_selector)). SetContent (intent)); Intent = new Intent (this, mylotteryactivity.class); Mtabhost.addtab (Mtabhost.newtabspec ("Tab3"). Setindicator (GetString (r.string.mylottery_indicator), Getresou RCEs (). getdrawable (R.drawable.mylottery_indicator_selector)). SetContent (intent)); Intent = new Intent (this, moreactivity.class); Mtabhost.addtab (Mtabhost.newtabspec ("Tab4"). Setindicator (GetString (R.string.more_indicator), Getresources ( ). Getdrawable (R.drawable.more_indicator_selector)). SetContent (intent)); }}3.