62

透明なタブを使用してActionBarを作成したいと思います#3b000000。このようなものですが、ActionBarの下にタブがあります。

ここに画像の説明を入力してください

これは私が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>

何が起こるかというと、ActionBar自体透明な背景色を表示しますが、タブは完全に透明です(色は表示されません)。

どうすればこれを解決できますか?

4

9 に答える 9

138

あなたの:を呼び出しsetStackedBackgroundDrawable()ます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")));

これにより、(例として、いくつかのランダムなアイコンとタブ、および効果を強調するための2つの異なる青みがかった背景色)が生成されます。

ここに画像の説明を入力してください

(更新アイコンはデフォルトのアイコンで、わずかな透明度があります。他のアイコンは、色が#FFFFFFFFのカスタムテストアイコンです。つまり、透明度はありません)。

于 2012-12-13T07:14:30.273 に答える
12

私はプロジェクトでこれを行いましたが、スタイルは次のようになりました。

<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>
于 2012-12-11T13:12:59.530 に答える
9

この記事で述べたように、次のカスタムテーマを使用すると問題なく機能します。

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

色合いを適用するために、Gunnarの答えはその方法を示しています。

ActionBar actionBar = getActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#330000ff")));
actionBar.setStackedBackgroundDrawable(new ColorDrawable(Color.parseColor("#550000ff")));
于 2014-11-25T13:43:10.687 に答える
8

これが完全に透明なアクションバーへの私のコードです

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

ここに画像の説明を入力してください

于 2014-05-28T06:45:42.880 に答える
4
             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);

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>
于 2015-01-09T14:47:25.747 に答える
0

テーマのアクションバーを背景画像または色として透明に設定するには、それを実装するための最良かつ簡単な方法を示す必要があります。

        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);
于 2016-01-14T16:11:01.107 に答える
0
ActionBar actionBar = getSupportActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));

それは私にとってうまくいきました

于 2016-07-18T02:49:28.280 に答える
0

ActionBarこれは、透明にするための私のケースではうまく機能しています。

getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor("#330000ff")));
getSupportActionBar().setStackedBackgroundDrawable(new ColorDrawable(Color.parseColor("#550000ff")));
于 2017-11-07T11:06:35.230 に答える
-1

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

透明な色/アクションバーと色/タブバーの色の値

于 2014-08-13T23:05:31.747 に答える