Tab Layout(选项卡布局)
Tab Layout(选项卡布局):http://hualang.iteye.com/blog/976826
参考:http://book.51cto.com/art/201007/214806.htm
所有讲解可以参考上面两个地址。
三个对应tab的Activity
资源文件:
res/drawable-hdpi下面存放myimage1.png,myimage2.png两个黑白相应的图片,以及ic_tab_artists.xml
main.xml
主程序package com.pandy.layout;import android.app.TabActivity;import android.content.Intent;import android.content.res.Resources;import android.os.Bundle;import android.widget.TabHost;public class TabLayoutDemoActivity extends TabActivity {public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Resources res = getResources(); // Resource object to get Drawables TabHost tabHost = getTabHost(); // The activity TabHost TabHost.TabSpec spec; // Resusable TabSpec for each tab Intent intent; // Reusable Intent for each tab // Create an Intent to launch an Activity for the tab (to be reused) intent = new Intent().setClass(this, ArtistsActivity.class); // Initialize a TabSpec for each tab and add it to the TabHost spec = tabHost.newTabSpec("tab1").setIndicator("标题一",res.getDrawable(R.drawable.myimage1)).setContent(intent); tabHost.addTab(spec); // Do the same for the other tabs intent = new Intent().setClass(this, AlbumsActivity.class); spec = tabHost.newTabSpec("tab2").setIndicator("标题二",res.getDrawable(R.drawable.myimage1)).setContent(intent); tabHost.addTab(spec); intent = new Intent().setClass(this, SongsActivity.class); spec = tabHost.newTabSpec("tab3").setIndicator("标题三",res.getDrawable(R.drawable.myimage1)).setContent(intent); tabHost.addTab(spec); tabHost.setCurrentTab(1);// 或采用如下的代码// getTabHost().setCurrentTabByTag("tab3"); } }