zoukankan      html  css  js  c++  java
  • Android学习之路十四:TabHost

      Android中的Tab选项卡,如TabHost,实现它可以继承TabActivity,当然也可以直接继承Activity。本TabActivity就是一个已经分页的Activity。

      

      案例:

      XML代码:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
    
        <TabHost
            android:id="@+id/tabHost"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content">
            <FrameLayout
                android:id="@android:id/tabcontent"
                android:paddingTop="80px"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content">
                <TextView
                    android:id="@+id/first_page"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:text="@string/first_page"/>
                <TextView
                    android:id="@+id/second_page"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:text="@string/second_page"/>
            </FrameLayout>"
        </TabHost>
    
    </LinearLayout>

       java代码:

      

    first_page = (TextView) findViewById(R.id.first_page);
            second_page = (TextView) findViewById(R.id.second_page);
            TabHost th = (TabHost) findViewById(R.id.tabHost);
            TabHost.TabSpec ts = th.newTabSpec("0");
            ts.setContent(R.id.first_page);
            ts.setIndicator(this.getString(R.id.first_page));
            th.addTab(ts);
            ts = th.newTabSpec("1");
            ts.setContent(R.id.second_page);
            ts.setIndicator(this.getString(R.id.second_page));
            th.addTab(ts);
            th.setCurrentTab(0);
  • 相关阅读:
    JavaScript之图片操作7
    JavaScript之图片操作6
    【数据结构】树
    【数据结构】查找
    【数据结构】排序
    【HTML】常用标签及属性
    【数据结构】堆栈
    【计算机网络】五层体系结构
    【Linux】相关英文缩写含义
    【Java】连接数据库MySQL
  • 原文地址:https://www.cnblogs.com/thinksasa/p/2919739.html
Copyright © 2011-2022 走看看