xml
-----------------------------------
<?xml version="1.0" encoding="utf-8" ?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout android:id="@+id/widget_layout_Bule"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<TextView android:id="@+id/tvTmp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="这是我在第一个tab上显示的文本"
android:textSize="18dp"
/>
<Button android:id="@+id/btnTmp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
/>
</LinearLayout>
<LinearLayout android:id="@+id/widget_layout_red"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<AnalogClock android:id="@+id/acTmp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout android:id="@+id/widget_layout_green"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<RadioButton android:id="@+id/rbtnTmp01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RadioButton"
/>
<RadioButton android:id="@+id/rbtnTmp02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RadioButton"
/>
</LinearLayout>
</FrameLayout>
java
-------------------------------
package com.example.huanglifeng.menudemo;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.TabActivity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.SimpleAdapter;
import android.widget.Spinner;
import android.widget.TabHost;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
public class MainActivity extends TabActivity implements TabHost.OnTabChangeListener {
private TabHost myTabHost;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_main);
myTabHost= this.getTabHost();
LayoutInflater.from(this).inflate(R.layout.activity_main,myTabHost.getTabContentView(),true);
myTabHost.setBackgroundColor(Color.argb(150,22,70,150));
myTabHost.addTab(myTabHost.newTabSpec("One")
.setIndicator("tab1",getResources().getDrawable(R.drawable.smile))
.setContent(R.id.widget_layout_Bule));
myTabHost.addTab(myTabHost.newTabSpec("Two")
.setIndicator("tab2",getResources().getDrawable(R.drawable.smile))
.setContent(R.id.widget_layout_red)
);
myTabHost.addTab(myTabHost.newTabSpec("Three")
.setIndicator("tab3",getResources().getDrawable(R.drawable.smile))
.setContent(R.id.widget_layout_green)
);
myTabHost.setOnTabChangedListener(this);
}
@Override
public void onTabChanged(String tagString) {
if (tagString.equals("One")) {
} else if (tagString.equals("Two")) {
} else {
}
}
}