Code example for ActionBarActivity

0
 
/** 
 * This demonstrates the use of action bar tabs and how they interact 
 * with other action bar features. 
 */ 
public class ActionBarTabs extends ActionBarActivity { 
    @Override 
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
 
        setContentView(R.layout.action_bar_tabs); 
    } 
 
    public void onAddTab(View v) {
        final ActionBar bar = getSupportActionBar();
        final int tabCount = bar.getTabCount();
        final String text = "Tab " + tabCount;
        bar.addTab(bar.newTab()
                .setText(text)
                .setTabListener(new TabListener(new TabContentFragment(text))));
    }