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

        

  • 相关阅读:
    thinkphp5.0与thinkphp3.2之间的区别
    比较数组大小
    PHP语言开发微信公众平台(订阅号)之curl命令(补充)
    ThinkPHP3.2.3快速入门:基础篇
    phpcms利用表单向导创建留言板(可以回复)
    Vijos P1782 借教室 ( 前缀和&&差分序列)
    HDU2648:Shopping(DKBR_hash)
    Codeforces Round #375 (Div. 2)
    BestCoder Round #88
    Codeforces Round #373 (Div. 2)
  • 原文地址:https://www.cnblogs.com/salam/p/1845036.html
Copyright © 2011-2022 走看看