Example usage for android.app ActionBar.Tab setCustomView

List of usage examples for android.app ActionBar.Tab setCustomView

Introduction

In this page you can find the example usage for android.app ActionBar.Tab setCustomView.

Prototype

public abstract void setCustomView(@LayoutRes int resId);

Source Link

Document

Set the action bar into custom navigation mode, supplying a view for custom navigation.

Usage

From source file:run.ace.TabBar.java

public void show(android.app.Activity activity) {
    //if (!(activity instanceof ActionBarActivity)) {
    android.app.ActionBar mainActionBar = activity.getActionBar();
    if (mainActionBar != null) {
        mainActionBar.show();/*from   w  w  w. ja  v a2 s .  c  o  m*/
        mainActionBar.setNavigationMode(android.app.ActionBar.NAVIGATION_MODE_TABS);
        if (_primaryCommands != null) {
            for (int i = 0; i < _primaryCommands.size(); i++) {
                android.app.ActionBar.Tab tab = mainActionBar.newTab();
                AppBarButton abb = (AppBarButton) _primaryCommands.get(i);
                if (abb.icon != null) {
                    tab.setCustomView(getCustomTabView(abb, mainActionBar.getThemedContext()));
                } else {
                    tab.setText(abb.label);
                }
                tab.setTabListener(this);
                mainActionBar.addTab(tab, i == 0);
            }
        }
        return;
    }
    throw new RuntimeException(
            "Cannot use TabBar on the main page in Android unless you set <preference name=\"ShowTitle\" value=\"true\"/> in config.xml.");
    //}
    //else {
    //    ActionBar actionBar = ((ActionBarActivity)activity).getSupportActionBar();
    //    if (actionBar != null) {
    //        actionBar.show();
    //        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    //        for (int i = 0; i < _primaryCommands.size(); i++) {
    //            ActionBar.Tab tab = actionBar.newTab();
    //            AppBarButton abb = (AppBarButton)_primaryCommands.get(i);
    //            if (abb.icon != null) {
    //                tab.setCustomView(getCustomTabView(abb, actionBar.getThemedContext()));
    //            }
    //            else {
    //                tab.setText(abb.label);
    //            }
    //            tab.setTabListener(this);
    //            actionBar.addTab(tab);
    //        }
    //        return;
    //    }
    //    throw new RuntimeException(
    //        "Unable to get TabBar from the current activity.");
    //}
}