Barra de acción transparente: tabcolor personalizado


Quiero crear una barra de acción con pestañas transparentes, con #3b000000. Algo como esto, pero con pestañas debajo de la barra de acción:

introduzca la descripción de la imagen aquí

Este es el código que estoy usando en 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>

Lo que sucede es que la barra de acción en sí hace mostrar el color de fondo transparente, pero las pestañas son totalmente transparentes (no hay color visible).

¿Cómo puedo resolver esto?

Author: nhaarman, 2012-12-05

9 answers

Llama setStackedBackgroundDrawable() a tu 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")));

Esto produce (como un ejemplo con algunos iconos y pestañas aleatorios, y dos colores de fondo azulado diferentes para resaltar el efecto):

introduzca la descripción de la imagen aquí

(El icono actualizar es el predeterminado, que viene con una ligera transparencia. Los otros iconos son iconos de prueba personalizados con color #FFFFFFFF, es decir, sin transparencia).

 136
Author: Gunnar Karlsson,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-12-14 01:30:47

He hecho esto en un proyecto y el estilo era así:

<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>
 12
Author: Marcio Covre,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-12-11 13:12:59

Como se mencionó en este artículo, el uso del siguiente tema personalizado funciona sin problemas.

<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>

Para aplicar algún tinte de color, la respuesta de Gunnar muestra cómo.

ActionBar actionBar = getActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#330000ff")));
actionBar.setStackedBackgroundDrawable(new ColorDrawable(Color.parseColor("#550000ff")));
 9
Author: Shashwat Black,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-11-25 13:43:10

Aquí está mi código para completamente transparente 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>

introduzca la descripción de la imagen aquí

 8
Author: I Love Coding,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-05-28 06:45:42
             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);

En estilo .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>
 4
Author: NickUnuchek,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-01-09 14:47:25

Para establecer cualquier barra de acción de tema transparente como imagen de fondo o color debe mostrarse la mejor manera mejor y fácil de implementarlo.

        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);
 0
Author: vivek,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-01-14 16:11:01
ActionBar actionBar = getSupportActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));

Funcionó bien para mí

 0
Author: bong jae choe,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-01-16 22:10:05

Esto está funcionando bien en mi caso para hacer ActionBar transparente.

getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#330000ff")));
getSupportActionBar().setStackedBackgroundDrawable(new ColorDrawable(Color.parseColor("#550000ff")));
 0
Author: Aashish,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-11-07 11:06:35

<!-- 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>

Valores de color/actionbar y color/tabbar que son transparentes

 -1
Author: luca992,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-08-13 23:05:31