Transparent Actionbar: custom tabcolor

AndroidActionbarsherlock

Android Problem Overview


I want to create an ActionBar with tabs that are transparent, with #3b000000. Something like this, but with tabs below the ActionBar:

enter image description here

This is the code I'm using in styles.xml:

<style name="Theme.MyTheme" parent="@style/Theme.Sherlock.Light.DarkActionBar">
    <item name="android:actionBarStyle">@style/ActionBar</item>
    <item name="windowActionBarOverlay">true</item>
    <item name="android:windowActionBarOverlay">true</item>
    <item name="actionBarStyle">@style/ActionBar</item>
</style>

<style name="ActionBar" parent="@style/Widget.Sherlock.Light.ActionBar">
    <item name="android:background">@color/actionbar</item>
    <item name="background">@color/actionbar</item>
    <item name="android:actionBarTabStyle">@style/ActionBarTabStyle</item>
    <item name="actionBarTabStyle">@style/ActionBarTabStyle</item>
</style>

<style name="ActionBarTabStyle" parent="@style/Widget.Sherlock.ActionBar.TabView">
    <item name="background">@color/actionbar_tabs</item>
    <item name="android:background">@color/actionbar_tabs</item>
</style>

What happens, is that the ActionBar itself does show the transparent backgroundcolor, but the tabs are totally transparent (no color visible).

How can I solve this?

Android Solutions


Solution 1 - Android

Call setStackedBackgroundDrawable() on your ActionBar:

getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
ActionBar actionBar = getActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#330000ff")));
actionBar.setStackedBackgroundDrawable(new ColorDrawable(Color.parseColor("#550000ff")));

This produces (as an example with some random icons and tabs, and two different bluish background colors to highlight the effect):

enter image description here

(The refresh icon is the default one, which comes with a slight transparency. The other icons are custom test icons with color #FFFFFFFF, that is, no transparency).

Solution 2 - Android

I have done this on an project and the style was like this:

<style name="AppTheme" parent="android:Theme.Holo">
    <item name="android:windowActionBarOverlay">true</item>
    <item name="android:actionBarStyle">@style/action_bar_theme</item>
    <item name="android:actionMenuTextColor">#fff</item>
</style>

<style name="action_bar_theme" parent="@android:style/Widget.Holo.ActionBar">
    <item name="android:background">#b3000000</item>
    <item name="android:titleTextStyle">@style/action_bar_text</item>
</style>

Solution 3 - Android

As mentioned in this article, using the following custom theme works flawlessly.

<resources>
    <!-- the theme applied to the application or activity -->
    <style name="CustomActionBarTheme"
           parent="@android:style/Theme.Holo">
        <item name="android:windowActionBarOverlay">true</item>
    </style>
</resources>

To apply some color tint, Gunnar's answer shows how.

ActionBar actionBar = getActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#330000ff")));
actionBar.setStackedBackgroundDrawable(new ColorDrawable(Color.parseColor("#550000ff")));

Solution 4 - Android

Here is my code to fully transparent Actionbar

<!-- Base application theme. -->
<style name="TransparentTheme" parent="android:Theme.Holo.Light">
    <!-- Customize your theme here. -->
    <item name="android:windowBackground">@null</item>
    <item name="android:actionBarStyle">@style/ActionBarStyle.Transparent</item>
    <item name="android:windowActionBarOverlay">true</item>
</style>

<style name="ActionBarStyle.Transparent" parent="android:Widget.ActionBar">
    <item name="android:background">@null</item>
    <item name="android:displayOptions">showHome|showTitle</item>
    <item name="android:titleTextStyle">@style/ActionBarStyle.Transparent.TitleTextStyle</item>
</style>

<style name="ActionBarStyle.Transparent.TitleTextStyle" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title">
    <item name="android:textColor">@android:color/white</item>
</style>

enter image description here

Solution 5 - Android

             getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);//or add in style.xml
             ActionBar actionBar = getActionBar();
			 
			 ColorDrawable newColor = new ColorDrawable(getResources().getColor(R.color.action_bar_color));//your color from res
			 newColor.setAlpha(128);//from 0(0%) to 256(100%)
			 getActionBar().setBackgroundDrawable(newColor);

in style.xml

<resources>
    <!-- the theme applied to the application or activity -->
    <style name="CustomActionBarTheme"
           parent="@android:style/Theme.Holo">
        <item name="android:windowActionBarOverlay">true</item>
    </style>
</resources>

Solution 6 - Android

To set any theme action bar transparent as background image or color should be shown the best best and easy way to implement it.

        actionBar.setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(activity, android.R.color.transparent)));


    ImageView image = new ImageView(this);
    image.setTag(R.string.decore_view);
    image.setAdjustViewBounds(true);
    image.setScaleType(ImageView.ScaleType.CENTER_CROP);
    image.setLayoutParams(new ViewGroup.LayoutParams(-1, -1));
    image.setImageResource(R.drawable.home_bg);
    ((ViewGroup)((ViewGroup)getWindow().getDecorView())).addView(image, 0);

Solution 7 - Android

ActionBar actionBar = getSupportActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));

it worked well for me

Solution 8 - Android

This is working fine on my case for making ActionBar transparent.

getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#330000ff")));
getSupportActionBar().setStackedBackgroundDrawable(new ColorDrawable(Color.parseColor("#550000ff")));

Solution 9 - Android

<!-- Base application theme. -->
<style name="AppTheme" parent="android:Theme.Holo.Light">
    <item name="android:actionBarStyle">@style/MyActionBar</item>
    <item name="android:actionBarTabBarStyle">@style/MyActionBarTabBar</item>
    <item name="android:windowActionBarOverlay">true</item>
</style>

<style name="MyActionBar"
    parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
    <item name="android:titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
    <item name="android:background">@color/actionbar</item>
    <item name="android:backgroundStacked">@color/tabbar</item>


</style>

color/actionbar and color/tabbar color values which are transparent

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionnhaarmanView Question on Stackoverflow
Solution 1 - AndroidonosendaiView Answer on Stackoverflow
Solution 2 - AndroidMarcio CovreView Answer on Stackoverflow
Solution 3 - AndroidShashwat BlackView Answer on Stackoverflow
Solution 4 - AndroidI Love CodingView Answer on Stackoverflow
Solution 5 - AndroidNickUnuchekView Answer on Stackoverflow
Solution 6 - AndroidvivekView Answer on Stackoverflow
Solution 7 - Android최봉재View Answer on Stackoverflow
Solution 8 - AndroidAashish KumarView Answer on Stackoverflow
Solution 9 - Androidluca992View Answer on Stackoverflow