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

        

  • 相关阅读:
    ThinkSNS+ PHP开发概述
    基础知识--封装、继承、多态、抽象
    读书笔记--《你在为谁工作》
    深入理解设计模式(终):总结--设计模式是药,没病就不要吃药
    深入理解设计模式(24):外观模式
    深入理解设计模式(23):代理模式
    深入理解设计模式(22):享元模式
    深入理解设计模式(21):组合模式
    深入理解设计模式(20):桥接模式
    深入理解设计模式(19):装饰模式
  • 原文地址:https://www.cnblogs.com/salam/p/1845036.html
Copyright © 2011-2022 走看看