android activity tabhost

在activity中使用tab

<?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/tabhost" android:layout_width="fill_parent"
		android:layout_height="fill_parent">
		<TabWidget
             android:id="@android:id/tabs"
             android:layout_width="fill_parent"
             android:layout_height="60px"            
             android:paddingBottom="10dip"
         /> 
         
         <FrameLayout
             android:id="@android:id/tabcontent"
             android:layout_width="fill_parent"
             android:layout_height="fill_parent"
             android:paddingTop="60px"> 
		<TextView android:id="@+id/view1" android:background="@drawable/blue"
			android:layout_width="fill_parent" android:layout_height="fill_parent"
			android:text="@string/tabs_1_tab_1" />

		<TextView android:id="@+id/view2" android:background="@drawable/red"
			android:layout_width="fill_parent" android:layout_height="fill_parent"
			android:text="@string/tabs_1_tab_2" />
			</FrameLayout>
	</TabHost>
</LinearLayout>



以下是java代码
@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		host=(TabHost) findViewById(R.id.tabhost);
		host.setup();
//		LayoutInflater.from(this).inflate(R.layout.main,
//				host.getTabContentView(), true);
		host.addTab(host.newTabSpec("1").setContent(R.id.view1).setIndicator("1"));
		host.addTab(host.newTabSpec("2").setContent(R.id.view2).setIndicator("2"));
	}

你可能感兴趣的:(java,android,xml)