zoukankan      html  css  js  c++  java
  • Android 控件之TabHost Tab页

    TabHost用来显示Tab页,先看效果

    源码下载

    一概述

        提供Tab页的窗口视图容器,它有俩个children,一组是用户可以选择指定Tab页的标签,另一组是FrameLayout用来显示该Tab页的内容。个别元素通常控制使用这个容器对象,而不是设置在子元素本身的值。

    二、重要方法

        addTab(TabHost.TabSpec tabSpec):添加一项Tab页

        clearAllTabs():清除所有与之相关联的Tab页.

        getCurrentTab():返回当前Tab页.

        getTabContentView():返回包含内容的FrameLayout

        newTabSpec(String tag):返回一个与之关联的新的TabSpec

    三、实例

    1.布局文件,需要使用FrameLayout

    <?xml version="1.0" encoding="utf-8"?>
    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView android:id="@+id/view1"
            android:background="@drawable/b"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="页1"/>

        <TextView android:id="@+id/view2"
            android:background="@drawable/c"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="页2"/>

        <TextView android:id="@+id/view3"
            android:background="@drawable/d"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="页3"/>

    </FrameLayout>

     2.继承TabActivity

    public class TabHostDemo extends TabActivity

    3.获取次此abHost

     TabHost tabHost = getTabHost();

    4.设置布局

    LayoutInflater.from(this).inflate(R.layout.tabhostpage, tabHost.getTabContentView(), true);

    5.添加Tab页

     tabHost.addTab(tabHost.newTabSpec("tab1")
                     .setIndicator("tab1")
                     .setContent(R.id.view1));
             tabHost.addTab(tabHost.newTabSpec("tab3")
                     .setIndicator("tab2")
                     .setContent(R.id.view2));
             tabHost.addTab(tabHost.newTabSpec("tab3")
                     .setIndicator("tab3")
                     .setContent(R.id.view3));

        

  • 相关阅读:
    RFM模型
    mysql日期函数(时间函数)
    数据库探索
    anaconhda安装步骤
    mysql安装和环境配置
    mysql时间条件查询
    mysql自连接
    mysql查询注意事项(查询优化)
    mysql常见的保留字和反引号使用
    多表联合查询注意事项(索引)
  • 原文地址:https://www.cnblogs.com/salam/p/1845036.html
Copyright © 2011-2022 走看看