整合MapActivity和TabActivity

 

 
import android.app.TabActivity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
public class TabDlg extends TabActivity
{
 //声明TabHost对象
 TabHost mTabHost;
 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState)
 {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.tab_dlg);
 
  //取得TabHost对象
  mTabHost = getTabHost();
    
  /* 为TabHost添加标签 */
 
  TabSpec spec = mTabHost.newTabSpec("map");//设置内容(setContent)
  spec.setIndicator("MapView",getResources().getDrawable(R.drawable.img1));//设置其标签和图标(setIndicator)
  Intent intent = new Intent(TabDlg.this,MapDlg.class);//设置内容(setContent)
  spec.setContent(intent);
  mTabHost.addTab(spec);
 
 
  TabSpec spec1 = mTabHost.newTabSpec("test");
  spec1.setIndicator("TestView",getResources().getDrawable(R.drawable.img2));
  Intent intent1 = new Intent(TabDlg.this,TestDlg.class);
  spec1.setContent(intent1);
  mTabHost.addTab(spec1);
 
    
     //设置TabHost的背景颜色
     mTabHost.setBackgroundColor(Color.argb(150, 22, 70, 150));
     //设置TabHost的背景图片资源
     mTabHost.setBackgroundResource(R.drawable.bg0);
    
     //设置当前显示哪一个标签
     mTabHost.setCurrentTab(0);
 }
}

 

//-----------------------------------------------------

 


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


public class TestDlg extends Activity
{

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

 

 


//-------------------------------------------------------------

 


import com.google.android.maps.MapActivity;
import android.os.Bundle;


public class MapDlg extends MapActivity
{

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

 @Override
 protected boolean isRouteDisplayed()
 {
  // TODO Auto-generated method stub
  return false;
 }

}

 

 

//------------------------------------------------------------- AndroidManifest.xml

 

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
 package="com.yarin.android.Examples_04_29" android:versionCode="1"
 android:versionName="1.0">
 <application android:icon="@drawable/img3" android:label="Tab+Map">
  <uses-library android:name="com.google.android.maps" />
  <activity android:name="TabDlg">
   <intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
   </intent-filter>
  </activity>
  <activity android:name="MapDlg" />
  <activity android:name="TestDlg" />
 </application>
 <uses-permission android:name="android.permission.INTERNET" />
 <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
 <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
 <uses-sdk android:minSdkVersion="8" />
</manifest>

 

 

//------------------------------------------------------------- tab_dlg.xml

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

 

//------------------------------------------------------------- map_dlg.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">
 <view class="com.google.android.maps.MapView" android:id="@+id/MapView"
  android:layout_width="fill_parent" android:layout_height="fill_parent"
  android:enabled="true" android:clickable="true"
  android:apiKey="0aL0-p7auCvls36_VhU6WVAvTXbwMsuBSyaqZug" />
</LinearLayout>


//------------------------------------------------------------- test_dlg.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" android:label="This is TestDlg">
 <TextView android:id="@+id/test_dlg_textview" android:layout_width="fill_parent"
  android:layout_height="wrap_content" android:text="This is a TestDlg" />
</LinearLayout>

 

你可能感兴趣的:(整合MapActivity和TabActivity)