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));

        

  • 相关阅读:
    BZOJ2741:[FOTILE模拟赛]L
    BZOJ3996:[TJOI2015]线性代数
    BZOJ3876:[AHOI2014]支线剧情
    BZOJ1861:[ZJOI2006]Book书架
    BZOJ3190:[JLOI2013]赛车
    HDU-1540 Tunnel Warfare 【线段树+单点修改+区间更新】
    HDU-1846 Brave Game 【巴什博弈】
    HDU-1421 搬寝室 【DP】
    HDU-4734 F(x) 【数位DP】
    AHU-412 Bessie Come Home 【Dijkstra】
  • 原文地址:https://www.cnblogs.com/salam/p/1845036.html
Copyright © 2011-2022 走看看