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);
  • 相关阅读:
    数据类型
    java基础
    Codeforces Round #655 (Div. 2) B. Omkar and Last Class of Math(数论)
    Codeforces Round #655 (Div. 2) A. Omkar and Completion(构造)
    LibreOJ
    QT入门-QMainWindow类
    WCF 请求与响应参数大小设置
    Python 代码性能优化技巧
    lists,tuples and sets of Python
    SQL Language
  • 原文地址:https://www.cnblogs.com/thinksasa/p/2919739.html
Copyright © 2011-2022 走看看