Search code examples
androidandroid-actionbaractionbarsherlock

How to change the indicator color of Sherlock Action Bar Tabs


I am making an android application where I need to change the indicator color of the ActionBarTabs. I am using the Sherlock library to achieve the ActionBarTabs.

How I can change the default indicator color of ActionBarTabs in Sherlock ActionBar ?

ActionBar actionBar = getSupportActionBar();

// Hide Actionbar Icon
actionBar.setDisplayShowHomeEnabled(false);

// Hide Actionbar Title
actionBar.setDisplayShowTitleEnabled(false);

// Create Actionbar Tabs
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

tariffPlanJSON = getIntent().getExtras().getString("jsondata");

try {
    JSONObject jsonObject = new JSONObject(tariffPlanJSON);
    JSONArray jsonArray = jsonObject.getJSONArray("payload");

    // going through the all tariff plans to see payload has which types of plans.
    for(int index = 0; index < jsonArray.length(); index++) {
        tariffPlan.add(jsonArray.getJSONObject(index).getString("plantype"));
    }

} catch (JSONException e) {
    e.printStackTrace();
}

Iterator<String> tariffPlansIterator = tariffPlan.iterator();
mActionBarTab = new Tab[tariffPlan.size()];

int index = 0;
while(tariffPlansIterator.hasNext()) {
    String planType = tariffPlansIterator.next();
    // creating a new tabs and setting the text to it.
    mActionBarTab[index] = actionBar.newTab().setText(planType);
    mActionBarTab[index].setTabListener(this);
    actionBar.addTab(mActionBarTab[index]);
    ++index;
}

Thanks in advance.


Solution

  • Use ActionbarStyleGenerator to style the Actionbar. This is by far the simplest and most intuitive way.

    How to:

    Use the UI to select colors for different items Once done click on "DOWNLOAD .ZIP" The ZIP file contains resource files that you have to copy in your project res/layout and res/drawableXXXX folders