- package cn.com.karl.music;
- import android.app.TabActivity;
- import android.content.Intent;
- import android.content.res.Resources;
- import android.os.Bundle;
- import android.view.Window;
- import android.view.WindowManager;
- import android.widget.TabHost;
-
- public class MainActivity extends TabActivity {
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- requestWindowFeature(Window.FEATURE_NO_TITLE);
- this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
- WindowManager.LayoutParams.FLAG_FULLSCREEN);
- setContentView(R.layout.main);
- Resources res = getResources();
- TabHost tabHost = getTabHost();
- TabHost.TabSpec spec;
- Intent intent;
- intent = new Intent().setClass(this, ListActivity.class);
- spec = tabHost.newTabSpec("music")
- .setIndicator("music", res.getDrawable(R.drawable.item))
- .setContent(intent);
- tabHost.addTab(spec);
- intent = new Intent().setClass(this, ArtistsActivity.class);
- spec = tabHost.newTabSpec("artist")
- .setIndicator("srtist", res.getDrawable(R.drawable.artist))
- .setContent(intent);
- tabHost.addTab(spec);
- intent = new Intent().setClass(this, AlbumsActivity.class);
- spec = tabHost.newTabSpec("special")
- .setIndicator("special", res.getDrawable(R.drawable.album))
- .setContent(intent);
- tabHost.addTab(spec);
- intent = new Intent().setClass(this, SongsActivity.class);
- spec = tabHost.newTabSpec("recent play")
- .setIndicator("recent play", res.getDrawable(R.drawable.album))
- .setContent(intent);
- tabHost.addTab(spec);
- tabHost.setCurrentTab(0);
- }
- }
页面布局:
- <?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:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:orientation="vertical"
- android:padding="5dp" >
- <TabWidget
- android:id="@android:id/tabs"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content" />
- <FrameLayout
- android:id="@android:id/tabcontent"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:padding="5dp" />
- </LinearLayout>
- </TabHost>