使用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。
使用方法与上面类型。
本文介绍了在Android应用中使用TabHost的两种方法:一是在XML布局文件中定义;二是通过继承TabActivity并调用getTabHost()方法。文章详细解释了TabHost、TabWidget和FrameLayout的使用方式及其ID要求。
319

被折叠的 条评论
为什么被折叠?



