Android 具有透明背景的自定义操作栏

Android 具有透明背景的自定义操作栏,android,background,android-actionbar,transparent,Android,Background,Android Actionbar,Transparent,我无法获得actionbar的透明背景。这是我的代码 <style name="AppTheme" parent="Theme.AppCompat.Light"> <item name="android:windowBackground">@android:color/transparent</item> <item name="android:windowActionBarOverlay">true</item>

我无法获得actionbar的透明背景。这是我的代码

    <style name="AppTheme" parent="Theme.AppCompat.Light">
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:windowActionBarOverlay">true</item>
    <item name="android:actionBarStyle">@style/action_bar_theme</item>
    <item name="android:windowContentOverlay">@android:color/transparent</item>
    </style>

<style name="action_bar_theme" parent="@style/Widget.AppCompat.ActionBar">
    <item name="android:background">@android:color/transparent</item>
    <item name="android:colorBackground">@android:color/transparent</item>
    <item name="android:titleTextStyle">@style/action_bar_title</item>
</style>

非常感谢您的帮助

在您的资源中创建自定义的hexcolor

<color name="custom_color">#8C000000</color> 
告诉我它是否有效

解决方案2:

仅适用于Android 3.0及更高版本

如果您的minSdkVersion设置为11或更高,您的自定义主题应使用theme.Holo主题(或其后代之一)作为父主题。例如:

<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>
<resources>
    <!-- the theme applied to the application or activity -->
    <style name="CustomActionBarTheme"
           parent="@android:style/Theme.AppCompat">
        <item name="android:windowActionBarOverlay">true</item>

        <!-- Support library compatibility -->
        <item name="windowActionBarOverlay">true</item>
    </style>
</resources>

真的
适用于Android 2.1及更高版本

如果您的应用程序在运行低于Android 3.0版本的设备上使用支持库以实现兼容性,则您的自定义主题应使用theme.AppCompat主题(或其子主题之一)作为父主题。例如:

<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>
<resources>
    <!-- the theme applied to the application or activity -->
    <style name="CustomActionBarTheme"
           parent="@android:style/Theme.AppCompat">
        <item name="android:windowActionBarOverlay">true</item>

        <!-- Support library compatibility -->
        <item name="windowActionBarOverlay">true</item>
    </style>
</resources>

真的
真的

Ref:

因为您使用的是在支持库中定义的小部件.AppCompat.ActionBar,所以android:xxx属性不可用。对于您的问题,只需删除
@style/action\u bar\u主题的前缀android:
@android:color/transparent

顺便说一下,出于同样的原因,请检查xml文件中的其他android:xxx attr

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

        <!-- Support library compatibility -->
        <item name="windowActionBarOverlay">true</item>
    </style>
</resources>