TabHost页卡

来源:互联网 发布:windows loader uefi 编辑:程序博客网 时间:2024/06/05 23:08

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));//响应事件,启动activityTabSpec 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);


0 0