user533844
user533844

Reputation: 2063

Android ActionBar Tab Color

I have added ActionBar tabs to my application. Default color for that underline is light blue. How do I change that color or style for selected tab ?

Upvotes: 24

Views: 31769

Answers (6)

Kenny Wyland
Kenny Wyland

Reputation: 21860

Here is a much easier way:

I've been struggling with this for days, but finally found the solution. I'm using AppCompat. You can set colorAccent in your theme and that will change the highlight color on your ActionBar. Like so:

<item name="colorAccent">@color/highlightcolor</item>

Here it is in context:

<style name="LightTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="colorPrimary">@color/darkgrey</item>
    <item name="colorPrimaryDark">@color/black</item>
    <item name="colorAccent">@color/highlightcolor</item>
</style>

Where I originally posted this answer: Android Tab underline color not changing

Upvotes: 3

Vinod Joshi
Vinod Joshi

Reputation: 7852

ActionBar bar = getActionBar();

bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

// set background for action bar
bar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#0c2354")));

// set background for action bar tab
bar.setStackedBackgroundDrawable(new ColorDrawable(Color.parseColor("#B5C0D0")));       

bar.show();

Upvotes: 7

Michal
Michal

Reputation: 2201

1) Generate the Action Bar Style, click Download ZIP to get the files

2) When you extract the zip file created in Step 1, you will get a res folder. Add this folder to your project under platform/android.

3) Modify manifest.xml to Use the New Action Bar Style, where "Action" is name of your style set in step 1.

<android xmlns:android="http://schemas.android.com/apk/res/android">      
<tool-api-level>14</tool-api-level>
<manifest>
    <application android:theme="@style/Theme.Action"/>
    <uses-sdk android:minSdkVersion="14"
        android:targetSdkVersion="16"/>
</manifest>
</android>

This manual helped me and I hope it will help you too.

Upvotes: 2

thomasdao
thomasdao

Reputation: 2957

For anyone wants to change actionbar color/background in code, you can do something like this

final ActionBar actionBar = getActionBar();
actionBar.setBackgroundDrawable(getResources().getDrawable(R.drawable.action_bar_bg));

To change the tab bar color under the actionbar:

actionBar.setStackedBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.color_brown_dark)));

To change tab bar background:

actionBar.setStackedBackgroundDrawable(getResources().getDrawable(
            R.drawable.coupon_header));

Upvotes: 98

Dori
Dori

Reputation: 18403

This may give some clues Action Bar Style Gen

Upvotes: 11

Terrance
Terrance

Reputation: 11862

selectableItemBackground is the attribute I think your looking for. I'd recommend you read this article about Customizing the Action Bar as well as look at this question on SO and this one as well.

In code i cant seem to find a way to customize the individual item selected but , customizing the bar itself would look something like this.

ActionBar bar = getActionBar();
bar.setBackgroundDrawable(new ColorDrawable("FF0000"));

Upvotes: 10

Related Questions