Today this article describes the top of the page at the bottom of the tab page has a special need for tabs! Obsolete activitygroup are used.
Look at the structure of the whole project as follows
The following describes the implementation process, the consistent style, concrete implementation or to see the comments, code is not a lot, it is not verbose.
Step1: First, the main interface Mainactivity.java
< Span style= "Font-family:courier New" >
Package Sun.geoffery.tabtopbottom;import Android.app.activitygroup;import Android.content.intent;import Android.graphics.color;import Android.os.bundle;import Android.view.window;import Android.widget.TabHost;import Android.widget.tabhost.tabspec;import Android.widget.tabwidget;import android.widget.textview;/** * All rights Reserved, designed by Geofferysun * * @Title: Mainactivity.java * @Package Sun.geoffery.tabtopbottom * @Description: Both top and bottom have t AB interface * @author: Geofferysun * @date: 2014-12-9 pm 3:41:04 * @version V1.0 */public class Mainactivity extends Activitygrou p {//define a Tabhost control private tabhost mtabhost;public void OnCreate (Bundle savedinstancestate) {// Set the hidden title bar requestwindowfeature (Window.feature_no_title); super.oncreate (savedinstancestate); SetContentView ( R.layout.activity_main);//Get tabhost layout mtabhost = (tabhost) Findviewbyid (r.id.tabhost); Mtabhost.setup ( This.getlocalactivitymanager ()); Tabspec _tab;_tab = Mtabhost.newtabspec ("Home"), _tab.setindicator ("First", Getresources (). getdrawablE (R.drawable.ic_launcher)); _tab.setcontent (New Intent (this, homeactivity.class)); Mtabhost.addtab (_tab); _tab = Mtabhost.newtabspec ("Order"); _tab.setindicator ("Orders", Getresources (). getdrawable (R.drawable.ic_launcher)); _ Tab.setcontent (New Intent (this, orderactivity.class)); Mtabhost.addtab (_tab); _tab = Mtabhost.newtabspec ("wallet"); _ Tab.setindicator ("Purse", getresources (). getdrawable (R.drawable.ic_launcher)); _tab.setcontent (New Intent (This, Walletactivity.class)); Mtabhost.addtab (_tab);//Set the first tab to be selected Mtabhost.setcurrenttab (0); Tabwidget tabwidget = Mtabhost.gettabwidget (); for (int i = 0; i < Tabwidget.getchildcount (); i++) {TextView TV = (TEXTV Iew) Tabwidget.getchildat (i). Findviewbyid (Android. R.id.title); Tv.settextcolor (Color.ltgray);//Setting the tab bar Font Color}}}
Step2: Layout file corresponding to the main page
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "Android:layout_width=" Fill_parent "android:layout_height=" fill_parent "android:orientation=" vertical "&G T <!--tab layout must be Tabhost--and <tabhost android:id= "@+id/tabhost" android:layout_width= "Fill_parent" android:layout_height= "Fill_parent" > <!--mosaic linear layout--<linearlayout Android:la Yout_width= "Fill_parent" android:layout_height= "fill_parent" android:orientation= "vertical" > <!--frame Layout--<framelayout android:id= "@android: Id/tabcontent" an Droid:layout_width= "Fill_parent" android:layout_height= "Wrap_content" android:layout_weight= "1"/> <!--tabwidget is the tab label using--<tabwidget android:id= "@and Roid:id/tabs "Android:layout_width= "Fill_parent" android:layout_height= "Wrap_content" Android:layout_weigh t= "0" android:background= "#404040"/> </LinearLayout> </tabhost></linearlayout& Gt
Step3: Normal separate page Homeactivity.java (and Walletactivity.java), nothing to do, just load a simple layout!
Package Sun.geoffery.tabtopbottom;import Android.app.activity;import Android.os.bundle;public class HomeActivity Extends Activity {public void OnCreate (Bundle savedinstancestate) { super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_simple); }}
step4: Normal separate page Homeactivity.java (and Walletactivity.java) layout file activity_simple.xml, nothing!
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android " android:layout_width=" match_parent " android:layout_height=" Match_parent " android: Background= "#FFCC00" android:orientation= "vertical" > </LinearLayout>
Step5: The point is, the top is also labeled tab page Orderactivity. java.
Package Sun.geoffery.tabtopbottom;import Android.app.activity;import Android.graphics.color;import Android.os.bundle;import Android.widget.tabhost;import Android.widget.tabwidget;import android.widget.TextView;/* * * All rights Reserved, designed by Geofferysun * @Title: Orderactivity.java * @Package Sun.geoffery.tabtopbottom * @D Escription: Top tab page * @author: Geofferysun * @date: 2014-12-9 pm 5:31:00 * @versionV1.0 */public class Orderactivity Exten DS Activity {private Tabhost mtabhost; public void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_tab); Mtabhost = (tabhost) Findviewbyid (r.id.mytabhost); Mtabhost.setup (); Tabwidget tabwidget = Mtabhost.gettabwidget () mtabhost.addtab (Mtabhost.newtabspec ("Pending Service"). Setindicator ("to Service"). SetContent (R.ID.PAGE0)); Mtabhost.addtab (Mtabhost.newtabspec ("completed"). Setindicator ("Completed"). SetContent (R.id.page1)) ; Mtabhost.addtab (Mtabhost.newtabspec ("Canceled"). SetindicatOr ("Canceled"). SetContent (R.id.page2)); int height = 120; int width = 45; for (int i=0;i<tabwidget.getchildcount (); i++) {//Set height, width, because the width is set to fill_parent, there is no effect on it tabwidget.getchildat (i). Getlayoutparams (). height=height;//sets the color of the title text in the tab, otherwise the default is black final TextView TV = (TextView) tabwidget.getchildat (i). Findviewbyid (Android. R.id.title); Tv.settextcolor (Color.ltgray);}}
STEP6: The Top tab page corresponds to the layout file activity_tab.xml.
<?xml version= "1.0" encoding= "Utf-8"? ><tabhost xmlns:android= "Http://schemas.android.com/apk/res/android "Android:id=" @+id/mytabhost "android:layout_width=" fill_parent "android:layout_height=" Fill_parent "> < LinearLayout android:layout_width= "fill_parent" android:layout_height= "Fill_parent" Android:orientati on= "vertical" > <tabwidget android:id= "@android: Id/tabs" android:layout_width= "Fill_par Ent "android:layout_height=" wrap_content "android:background=" #404040 "/> <!--note Framel Ayout/tabwidget Label Location--<framelayout android:id= "@android: Id/tabcontent" android:layou T_width= "Fill_parent" android:layout_height= "0DP" android:layout_weight= "1" > <text View android:id= "@+id/page0" android:layout_width= "Match_parent" Android:layo ut_height= "Match_parent" Android:background= "#6699FF" android:text= "Service page" > </TextView> <t Extview android:id= "@+id/page1" android:layout_width= "Match_parent" android:l ayout_height= "Match_parent" android:background= "#FF9900" android:text= "finished page" > </TextView> <textview android:id= "@+id/page2" Android:layout_width= "Ma Tch_parent "android:layout_height=" match_parent "android:background=" #99cc33 " android:text= "Canceled page" > </TextView> </FrameLayout> </LINEARLAYOUT></TABHOST&G T
STEP7: Finally, the manifest file manifest.xml.
<?xml version= "1.0" encoding= "Utf-8"? ><manifest xmlns:android= "http://schemas.android.com/apk/res/ Android "package=" Sun.geoffery.tabtopbottom "android:versioncode=" 1 "android:versionname=" 1.0 "> <uses-s DK android:minsdkversion= "android:targetsdkversion="/> <application Android:allowbac Kup= "true" android:icon= "@drawable/ic_launcher" android:label= "@string/app_name" Android:theme= "@styl E/apptheme "> <activity android:name=". Mainactivity "android:label=" @string/app_name "> <intent-filter> <action Android:name= "Android.intent.action.MAIN"/> <category android:name= "Android.intent.category.LAUNCHER "/> </intent-filter> </activity> <activity android:name=". Orderactivity "></activity> <activity android:name=". Homeactivity "></activity> <aCtivity android:name= ". Walletactivity "></activity> </application></manifest>
So far, all the code is ready to play!
Acquisition
Android Bottom Tabactivity (2)--activitygroup