80,493
社区成员
发帖
与我相关
我的任务
分享<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="2dp" />
</LinearLayout>
</TabHost>
public class LaunchActivity extends TabActivity {
/** Called when the activity is first created. */
public static TabHost tabHost;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tabHost = this.getTabHost();
TabHost.TabSpec spec;
Intent intent;
// 添加标签1
intent = new Intent().setClass(this, activity1.class);
spec = tabHost.newTabSpec("标签1").setIndicator("标签1", null)
.setContent(intent);
tabHost.addTab(spec);
// 添加标签2
intent = new Intent().setClass(this, activity2.class);
spec = tabHost.newTabSpec("标签2").setIndicator("标签2", null)
.setContent(intent);
tabHost.addTab(spec);
// 设置默认标签
tabHost.setCurrentTab(0);
}
}