FragmentTabHost simple example

Classification: Android finishing 225 people read Comment(2) Collection Report

Tab page layout R.layout.tabhost_layout:

Xmlns:android= "<LinearLayout"
Http:// "xmlns:tools="
Match_parent "android:layout_width="
Match_parent "android:layout_height="
Android:orientation= "vertical" >

@+id/tab_center_fl "android:id="
Match_parent "android:layout_width="
0dp "android:layout_height="
Android:layout_weight= "1" >

@+id/tabhost "android:id="
Match_parent "android:layout_width="
Wrap_content "android:layout_height="
Android:background= "#ff00ff" >

@+id/tabs "android:id="
Match_parent "android:layout_width="
Android:layout_height= "wrap_content" >

@+id/tab_content_fl "android:id="
Match_parent "android:layout_width="
Android:layout_height= "wrap_content" >


Interface code:

Class TabhostActivity extends FragmentActivity public {
FragmentTabHost mFragmentTabHost private;
@SuppressWarnings ("rawtypes")
Class fragmentArray[] private = {FragmentTabOne.class, FragmentTabTwo.class, FragmentTabThree.class,};
String titleArray[] private = {"Tab_One", "Tab_Two", "Tab_Three"};

Void onCreate protected (bundle Bundle) {
Auto-generated method stub / / TODO
Super.onCreate (bundle);
SetContentView (R.layout.tabhost_layout);
IntViews ();
InitTabHost ();

Void intViews private () {
MFragmentTabHost = (FragmentTabHost) findViewById (;

Void initTabHost private () {
MFragmentTabHost.setup (this, getSupportFragmentManager (),;
MFragmentTabHost.getTabWidget ().SetDividerDrawable (null);

Count int = fragmentArray.length;

For (I int = 0; I < count; i++) {
TabSpec TabHost.TabSpec = mFragmentTabHost.newTabSpec (titleArray[i]).SetIndicator (getTabBottomView (I));
MFragmentTabHost.addTab (tabSpec, fragmentArray[i], null);
MFragmentTabHost.getTabWidget (I).SetBackgroundResource (R.drawable.tab_bg).GetChildAt ();

View getTabBottomView private (index int) {
LayoutInflater LayoutInflater = LayoutInflater.from (this);
View view = layoutInflater.inflate (R.layout.tab_bottom_layout bottom layout of null); / / the layout is simple, is ID for the textview bottom TV
TextView TextView = (TextView) view.findViewById (;
TextView.setText (titleArray[index]);
View return;

Copyright statement: This article is the original article of the main Bo, without the permission of the owner.

Guess what you're looking for.
View comments
* above the user's comments only represent their personal views, do not represent the views or position of the CSDN website
    Personal data
    • Visit35848 times
    • Integral:1718
    • Grade
    • Rank:13145th
    • Original142
    • Reprint:36
    • Translation:1
    • Comment:9
    Latest comments