Tab page layout R.layout.tabhost_layout:
Xmlns:android= http://schemas.android.com/apk/res/android "<LinearLayout"
Http://schemas.android.com/tools "xmlns:tools="
Match_parent "android:layout_width="
Match_parent "android:layout_height="
Android:orientation= "vertical" >
<FrameLayout
@+id/tab_center_fl "android:id="
Match_parent "android:layout_width="
0dp "android:layout_height="
Android:layout_weight= "1" >
</FrameLayout>
<android.support.v4.app.FragmentTabHost
@+id/tabhost "android:id="
Match_parent "android:layout_width="
Wrap_content "android:layout_height="
Android:background= "#ff00ff" >
<TabHost
@+id/tabs "android:id="
Match_parent "android:layout_width="
Android:layout_height= "wrap_content" >
</TabHost>
<FrameLayout
@+id/tab_content_fl "android:id="
Match_parent "android:layout_width="
Android:layout_height= "wrap_content" >
</FrameLayout>
</android.support.v4.app.FragmentTabHost>
</LinearLayout>
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"};
@Override
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 (R.id.tabhost);
}
Void initTabHost private () {
MFragmentTabHost.setup (this, getSupportFragmentManager (), R.id.tab_content_fl);
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 (R.id.bottom_tv);
TextView.setText (titleArray[index]);
View return;
}
}
Copyright statement: This article is the original article of the main Bo, without the permission of the owner.
- On aSeveral ways of starting other applications in Android
- Next articleInstall JDK and AndroidStudio under Ubuntu system
- Top
- 0
- Step
- One
- Guess what you're looking for.