双11狂欢大促

盲盒赢 定制羽绒服

开启惊喜盲盒,抽取你的专属好礼

— 惊喜奖品抢先看 —

TabHost里面怎么添加控件

AllenZhang0516 AllenZhang0516 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
xml代码:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffcc00">
<TabHost
android:id="@+id/tabhost"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<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="wrap_content"
>
<TextView
android:id="@+id/t1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="蔬菜"/>
<TextView
android:id="@+id/t2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="水果"/>
<TextView
android:id="@+id/t3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="儿歌"/>
</FrameLayout>
</LinearLayout>
</TabHost>

</RelativeLayout>
java代码:
package com.example.study;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TabHost;
public class lei extends Activity{
private TabHost tabHost;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.lei);
tabHost = (TabHost) findViewById(R.id.tabhost);
tabHost.setup();
tabHost.addTab(tabHost.newTabSpec("蔬菜").setIndicator("蔬菜",
getResources().getDrawable(R.drawable.ic_launcher)).setContent(
R.id.t1));
tabHost.addTab(tabHost.newTabSpec("水果").setIndicator("水果")
.setContent(R.id.t2));
tabHost.addTab(tabHost.newTabSpec("儿歌").setIndicator("儿歌")
.setContent(R.id.t3));

}
}
我写的如上面的代码,实现了一个有三个tab的TabHost,怎么往Tab里面加入控件。
加入“水果”“蔬菜”的图片和“儿歌”。求解答!最好给个例子。
...全文
评论 1
收藏 已收藏
分享
返回顶部
AllenZhang0516
Android 80,489 成员 91,375 内容