TabHost页卡

TabHost 是一种布局,继承于FrameLayout 的;

由三部分组成:tabcontent+ title+tab; tabcontent 其实就是一个activity,由一层FrameLayout 包裹

TabHost /TabWidget//FrameLayout id为固定以下系统id

<?xml version="1.0" encoding="utf-8"?>
<!-- 外面那一层布局 -->
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    <span style="color:#990000;">android:id="@android:id/tabhost"</span>
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

<!-- 页卡tabs -->
<pre name="code" class="html"><!-- 属性visible=“gone”原本的tab消失且不占空间 -->
<TabWidget android:id="@android:id/tabs" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:background="@drawable/button_click_selector" > </TabWidget>

 

<!-- 内容区域 -->
    <FrameLayout
        <span style="color:#990000;">android:id="@android:id/tabcontent"</span>
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@android:id/tabs" >
    </FrameLayout>
    

</TabHost>

TabHost tabHost = getTabHost();
		//页卡标签,自定义页卡时,监听自定义控件时,用mTabHost.setCurrentTabByTag("tab1");将两者联系起来
		TabSpec tabspec1 = tabHost.newTabSpec("tab1");
		tabspec1.setIndicator("main");//设置tab页卡的名字
		tabspec1.setContent(new Intent(this, DefinedActivity.class));//响应事件,启动activity

		TabSpec tabspec2 = tabHost.newTabSpec("tab2");
		tabspec2.setIndicator("first");
		tabspec2.setContent(new Intent(this, ViewPagerActivity.class));

		TabSpec tabspec3 = tabHost.newTabSpec("tab3");
		tabspec3.setIndicator("last");
		tabspec3.setContent(new Intent(this, SimpleAdapterActivity.class));

		tabHost.addTab(tabspec1);
		tabHost.addTab(tabspec2);
		tabHost.addTab(tabspec3);


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值