zoukankan      html  css  js  c++  java
  • Android的TabActivity的使用

    TabActivity的使用步骤:

    一、在XML中布局好相应的布局,需要注意的是,布局中必须要包含有android:id="@android:id/tabhost",

      android:id="@android:id/tabs", android:id="@android:id/tabcontent"三个id。相应的布局例子如下:

    <?xml version="1.0" encoding="utf-8"?>
    <TabHost xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@android:id/tabhost"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/test1"
        tools:context=".SlideActivity" >
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical" >
    
            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:paddingLeft="1dip"
                android:paddingRight="1dip"
                android:paddingTop="4dip"
                android:textColor="@drawable/white" >
            </TabWidget>
    
            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="match_parent"
                android:layout_height="0dip"
                android:layout_weight="1" >
            </FrameLayout>
    
          </LinearLayout>
    </TabHost>

    二、先要定义一个TabHost变量,然后你的Activity要继承TabActivity而不是Activity

    三、然后初始化该变量,方法有两种,一种是调用系统的函数来获得,另一种是和获得其他控件一样,用ID获

      得。即mTabHost=(TabHost)findViewById(android.R.id.tabhost);

    四、然后向该Tabhost变量中添加相应的Tab,相应的添加方法如下:

      Intent intent = new Intent();

      Intent.setClass(本地的类名.this,想要启动的类名.class);

      TabSpec tabspec = mTabHost.newTabSpec(“相应的位置”);

      tabspec.setIndicator(标签名,图标);

      tabspec.setContent(intent);

      mTabHost.addTab(tabspec);

      注:当不是继承TabActivity的时候,必须在添加tab的时候先调用mTabHost的setup函数:

        mTabHost.setup(this.getLocalActivityManaget());

  • 相关阅读:
    第一次冲刺结果演示 一组评审总结
    检查博客情况
    第十次站立会议
    第九次站立会议
    暑期实训day4
    暑期实训day3
    暑期实训day2.1——一发空格引发的血案
    暑期实训day2
    暑期实训day1
    黑板模式
  • 原文地址:https://www.cnblogs.com/zds-song/p/3734212.html
Copyright © 2011-2022 走看看