0

I am working on Actionbar using Sherlock library. I want to change the Background Image of the Actionbar and Tabs differently. Currently I have changed the Background of the Actionbar successfully via codes at runtime:

Drawable myIcon = getResources().getDrawable(R.drawable.blue_menu_background);
mActionBar.setBackgroundDrawable(myIcon);

But I am getting problem with the Tab background. How can I change the Background of Tabs. Please suggest me.

Sam-In-TechValens
  • 2,501
  • 4
  • 34
  • 67

3 Answers3

9

you can use this code:

actionBar.setStackedBackgroundDrawable(new ColorDrawable(yourColor)); // for example new ColorDrawable(Color.BLUE)
Volodymyr Yatsykiv
  • 3,181
  • 1
  • 24
  • 28
2

Instead of doing that, you can use Style for Tabs:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <!-- the theme applied to the application or activity -->
    <style name="CustomActivityTheme" parent="@android:style/Theme.Holo">
        <item name="android:actionBarTabTextStyle">@style/CustomTabTextStyle</item>
        <item name="android:actionBarDivider">@drawable/ab_divider</item>
        <item name="android:actionBarItemBackground">@drawable/ab_item_background</item>
    </style>

    <!-- style for the action bar tab text -->
    <style name="CustomTabTextStyle" parent="@android:style/TextAppearance.Holo">
        <item name="android:textColor">#2456c2</item>
    </style>
</resources>

check this article for more details.

FMontano
  • 907
  • 8
  • 17
Dhaval Parmar
  • 18,812
  • 8
  • 82
  • 177
-1

To Change Actionbar Tab's color, Pls use this code:

//For Example if you want White color as Tabs background, then

getActionBar().setStackedBackgroundDrawable(new ColorDrawable(Color.parseColor("#FFFFFF")));
Srikanth P
  • 1,506
  • 14
  • 12