24 3월

탭(TabHost, TabWidget)

<?xml version="1.0" encoding="utf-8"?>
<tabhost android:id="@android:id/tabhost" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="fill_parent" android:layout_width="fill_parent">	
	<linearlayout android:layout_height="fill_parent" android:layout_width="fill_parent" android:orientation="vertical" android:padding="5dip">
		<tabwidget android:id="@android:id/tabs" android:layout_height="wrap_content" android:layout_width="fill_parent">				
		<framelayout android:id="@android:id/tabcontent" android:layout_height="fill_parent" android:layout_width="fill_parent" android:padding="5dip">
	</framelayout></tabwidget></linearlayout>
</tabhost>
public class TabTest extends TabActivity {

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.tab_test);

		TabHost mTab = getTabHost();
		Intent intent;

		intent = new Intent().setClass(this, Tab01.class);
		mTab.addTab(mTab.newTabSpec("tag1").setIndicator("TAB1").setContent(intent));

		intent = new Intent().setClass(this, Tab02.class);
		mTab.addTab(mTab.newTabSpec("tag2").setIndicator("TAB2").setContent(intent));

		intent = new Intent().setClass(this, Tab03.class);
		mTab.addTab(mTab.newTabSpec("tag3").setIndicator("TAB3").setContent(intent));

		mTab.setCurrentTab(0);
	}
}

답글 남기기

이메일은 공개되지 않습니다. 필수 입력창은 * 로 표시되어 있습니다.