0
votes

I'm doing a custom style for the action bar in my application. I've changed action bar to the blue background and white text that I wanted, and that works fine. However the area around the app's title and icon, which I think is the transparent region, is showing the general theme background instead of the action bar background. So instead of the transparency 'falling through' to the action bar, it's falling through to the base background.

Here's an image that displays the problem (I've changed the theme background to red to highlight the issue).

the problem

How can I resolve this?

Here's my styles.xml file:

<resources>

    <style name="MyTheme" parent="@style/Theme.AppCompat">
        <item name="android:background">#FF0000</item>
        <item name="android:textColor">@color/cp_text</item>
        <item name="android:actionBarStyle">@style/CustomActionBar</item>
        <item name="android:actionButtonStyle">@style/CustomActionBarButton</item>
        <item name="android:actionModeBackground">@color/cp_titlebar_background</item>
    </style>

    <style name="CustomActionBar" parent="@style/Widget.AppCompat.ActionBar">
        <item name="android:background">@color/cp_titlebar_background</item>
        <item name="android:textColor">@color/cp_text</item>
        <item name="android:titleTextStyle">@style/CPTitleTextStyle</item>
    </style>

    <style name="CPTitleTextStyle" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
        <item name="android:textColor">@color/cp_text</item>
        <item name="android:background">@color/cp_titlebar_background</item>
    </style>

    <style name="CustomActionBarButton" parent="@android:style/Widget.ActionButton">
        <item name="android:background">@color/cp_titlebar_background</item>
    </style>

</resources>
1

1 Answers

3
votes

By setting <item name="android:background">#FF0000</item> on your base theme, all views and widgets will use this value for their background.

If you are wanting to set the background colour for activities in your theme, then use the android:windowBackground attribute instead of background.