使用TabHost有两种办法
1.在layout的xml文件里定义,格式如下:
[color=red][size=medium][b]其中TabHost、TabWidget、FrameLayout的id必须如上,否则运行出错,甚至不能通过编译。
在代码中用[/b][/size][/color]
使用Tab.
2.继承TabActivity,从TabActivity中用getTabHost()方法获取TabHost。
使用方法与上面类型。
1.在layout的xml文件里定义,格式如下:
<?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:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<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">
</FrameLayout>
</LinearLayout>
</TabHost>
[color=red][size=medium][b]其中TabHost、TabWidget、FrameLayout的id必须如上,否则运行出错,甚至不能通过编译。
在代码中用[/b][/size][/color]
TabHost myTabHost = (TabHost) findViewById(R.id.tabhost);
TabWidget tabWidget = myTabHost.getTabWidget();
myTabHost.addTab(tabHost.newTabSpec("tab1")
.setIndicator("tab1", getResources().getDrawable(R.drawable.mumule))
.setContent(R.id.view1));
使用Tab.
2.继承TabActivity,从TabActivity中用getTabHost()方法获取TabHost。
使用方法与上面类型。