对Android中Tab的使用总结
程序员文章站
2022-07-13 12:52:14
...
package com.eric.LinearLayout; import android.app.TabActivity; import android.content.Intent; import android.os.Bundle; import android.view.LayoutInflater; import android.widget.TabHost; import android.widget.TextView; import com.eric.R; /** * 对tab的选择按钮的测试及终结 创建人: 创建时间:2011-6-24 * * @author chenhaodejia * */ public class HelloTabWidget extends TabActivity { // TabActivity @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); /* * TabHost tabHost = getTabHost(); * LayoutInflater.from(this).inflate(R.layout.tab_1, * tabHost.getTabContentView(), true); * tabHost.addTab(tabHost.newTabSpec( * "tab1").setIndicator("tab1").setContent(R.id.textview1)); * * //添加tab * tabHost.addTab(tabHost.newTabSpec("tab_test2").setIndicator("TAB 2" * ).setContent(R.id.textview1)); * tabHost.addTab(tabHost.newTabSpec("tab_test3" * ).setIndicator("TAB 3").setContent(R.id.textview2)); * tabHost.addTab(tabHost * .newTabSpec("tab_test4").setIndicator("TAB 4").setContent * (R.id.textview3)); tabHost.setCurrentTab(1); * //默认需要选中那一个tab,就填写一个tab的index,这里的tab的index是以o开始的 */ /* * //给tab添加图片 TabHost tabHost = getTabHost(); * LayoutInflater.from(this).inflate(R.layout.tab_1, * tabHost.getTabContentView(), true); * tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("tab1", * getResources * ().getDrawable(R.drawable.baob1)).setContent(R.id.textview1)); * tabHost * .addTab(tabHost.newTabSpec("tab_test1").setIndicator("TAB 1").setContent * (R.id.textview2)); * tabHost.addTab(tabHost.newTabSpec("tab_test2").setIndicator * ("TAB 2").setContent(R.id.textview3)); tabHost.setCurrentTab(0); */ /* * //给tab赋值窗体,在点击tab的时候,在下面显示一个Form,进行需要的处理 final TabHost tabHost = * getTabHost(); LayoutInflater.from(this).inflate(R.layout.tab_1, * tabHost.getTabContentView(), true); * tabHost.addTab(tabHost.newTabSpec( * "tab1").setIndicator("list").setContent(new Intent(this, * FormStuff.class))); * tabHost.addTab(tabHost.newTabSpec("tab_test2").setIndicator * ("TAB 2").setContent(new Intent(this, TableLayout.class))); * tabHost.addTab * (tabHost.newTabSpec("tab_test1").setIndicator("TAB 1").setContent * (R.id.textview2)); * tabHost.addTab(tabHost.newTabSpec("tab_test2").setIndicator * ("TAB 2").setContent(R.id.textview3)); tabHost.setCurrentTab(1); */ // 对上面三种tab形式的整合 TabHost tabHost = getTabHost(); LayoutInflater.from(this).inflate(R.layout.tab_1, tabHost.getTabContentView(), true); tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("tab1", getResources().getDrawable(R.drawable.baob1)).setContent( new Intent(this, TableLayout.class))); tabHost.addTab(tabHost.newTabSpec("tab_test2").setIndicator("TAB 2", getResources().getDrawable(R.drawable.baob2)).setContent( new Intent(this, FormStuff.class))); tabHost.addTab(tabHost.newTabSpec("tab_test3").setIndicator("TAB 3", getResources().getDrawable(R.drawable.baob3)).setContent( R.id.textview2)); tabHost.addTab(tabHost.newTabSpec("tab_test4").setIndicator("TAB 4", getResources().getDrawable(R.drawable.baob4)).setContent( R.id.textview3)); tabHost.setCurrentTab(0); } }