透明的动作条:自定义tabcolor自定义、透明、动作、tabcolor

2023-09-11 20:15:48 作者:欲言又止i

我想创建一个标签,是透明的,与#3b000000 的动作条。事情是这样的,但随着动作条以下标签:

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

这是我使用的styles.xml的code:

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>

会发生什么事,就是动作条本身的确实的展现透明的backgroundColor,但标签是完全透明的(无颜色可见)。

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?

推荐答案

呼叫 setStackedBackgroundDrawable()动作条

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

(刷新图标是默认的,附带有轻微的透明度,其它图标是定制的测试的图标,颜色#FFFFFFFF,即不透明度)。

(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).