使用ActivityGroup实现Tab在底部

来源:互联网 发布:智行火车票小程序源码 编辑:程序博客网 时间:2024/06/05 16:42

TabActivity

 

package com.wai.tab;

import android.app.ActivityGroup;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;

public class TabActivity extends ActivityGroup {

 public static TabHost tab_host;

 @Override
 protected void onCreate(Bundle savedInstanceState) {

  super.onCreate(savedInstanceState);

  setContentView(R.layout.main);

  tab_host = (TabHost) findViewById(R.id.edit_item_tab_host);

  tab_host.setup(this.getLocalActivityManager());
  
  TabSpec ts1 = tab_host.newTabSpec("TAB_WEATHER");

  ts1.setIndicator("Weather");

  ts1.setContent(new Intent(this, Weather.class));

  tab_host.addTab(ts1);

  TabSpec ts2 = tab_host.newTabSpec("TAB_MAIL");

  ts2.setIndicator("Mail");

  ts2.setContent(new Intent(this, MailSend.class));

  tab_host.addTab(ts2);

  TabSpec ts3 = tab_host.newTabSpec("TAB_JUMP");

  ts3.setIndicator("Jump");

  ts3.setContent(new Intent(this, TabJump.class));

  tab_host.addTab(ts3);

  tab_host.setCurrentTab(0);

 }

}

 

 

MailSend

 

package com.wai.tab;

import android.app.Activity;
import android.os.Bundle;

public class MailSend extends Activity {

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main2);
 }
}

 

 

TabJump

 

package com.wai.tab;

import android.app.Activity;
import android.os.Bundle;

public class TabJump extends Activity {

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main1);
 }
}

 

 

Weather

 

package com.wai.tab;

import android.app.Activity;
import android.os.Bundle;

public class Weather extends Activity {

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main3);
 }
}

 

 

 

main.xml

 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical" android:layout_width="fill_parent"
  android:layout_height="fill_parent">
  <TabHost android:id="@+id/edit_item_tab_host"
   android:layout_width="fill_parent" android:layout_height="fill_parent">
   <LinearLayout android:orientation="vertical"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:padding="5dp">
    <FrameLayout android:id="@android:id/tabcontent"
     android:layout_width="fill_parent" android:layout_height="wrap_content"
     android:padding="5dp" android:layout_weight="1" />
    <TabWidget android:id="@android:id/tabs"
     android:layout_width="fill_parent" android:layout_height="wrap_content"
     android:layout_weight="0" />
   </LinearLayout>
  </TabHost>
</LinearLayout>

 

 

 

 

main1.xml

 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical" android:layout_width="fill_parent"
  android:layout_height="fill_parent">
  <TextView android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center" android:text="this is the MailSend"></TextView>
</LinearLayout>

 

 

 

main2.xml

 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical" android:layout_width="fill_parent"
  android:layout_height="fill_parent">
  <TextView android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center" android:text="this is the MailSend"></TextView>
</LinearLayout>

 

 

 

 

main3.xml

 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical" android:layout_width="fill_parent"
  android:layout_height="fill_parent">
  <TextView android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center" android:text="this is the Weather"></TextView>
</LinearLayout>

 

 

 

androidManifest.xml

 

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.wai.tab"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".TabActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
 <activity android:name=".MailSend"></activity>
 <activity android:name=".TabJump"></activity>
 <activity android:name=".Weather"></activity>
    </application>
    <uses-sdk android:minSdkVersion="8" />

</manifest>

 

 

原创粉丝点击