ActionBar.Tab
1.添加Tab
1 import com.actionbarsherlock.app.ActionBar.Tab; 2 @Override 3 protected void onCreate(Bundle savedInstanceState) { 4 // TODO Auto-generated method stub 5 setTheme(R.style.Theme_Sherlock); 6 super.onCreate(savedInstanceState); 7 /** 8 * 隐藏标题和图标 9 */ 10 getSupportActionBar().setDisplayShowTitleEnabled(false); 11 getSupportActionBar().setDisplayShowHomeEnabled(false); 12 // 设置显示tab 13 getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); 14 /** 15 * 添加Tab并添加点击事件 16 */ 17 for (int i = 0; i <= 3; i++) { 18 ActionBar.Tab tab = getSupportActionBar().newTab(); 19 tab.setText("Tab " + i); 20 tab.setTabListener(this); 21 getSupportActionBar().addTab(tab); 22 } 23 }
2.事件回调监听
1 implements ActionBar.TabListener 2 /** 3 * 选择回调事件 4 */ 5 @Override 6 public void onTabSelected(Tab tab, FragmentTransaction ft) { 7 // TODO Auto-generated method stub 8 9 } 10 11 @Override 12 public void onTabUnselected(Tab tab, FragmentTransaction ft) { 13 // TODO Auto-generated method stub 14 15 } 16 17 @Override 18 public void onTabReselected(Tab tab, FragmentTransaction ft) { 19 // TODO Auto-generated method stub 20 21 }