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

  • 相关阅读:
    【转贴】SMP、NUMA、MPP体系结构介绍
    【转贴】内存重要参数详解 RAS CAS
    【转贴】内存系列二:深入理解硬件原理
    [百度]将ftp添加到本地映射磁盘的方法
    [百家号]7nm ARM 64核!华为Hi1620高性能CPU公开:3.0GHz
    CISCO系列交换机如何清空配置
    绝对实用 NAT + VLAN +ACL管理企业网络
    思科 vlan 相关操作
    思科路由器的密码忘记了用简单的命令来重置思科路由器密码
    字符串驱动技术—— MethodAddress , MethodName , ObjectInvoke
  • 原文地址:https://www.cnblogs.com/zds-song/p/3734212.html
Copyright © 2011-2022 走看看