[android] Setting Android Theme background color

I'm trying to modify the default background theme color, which should be easy but surprisingly I can't get it working. Please note that I want the change to be across the entire app, not just for a single activity. Here is my code:

styles.xml

<resources>

    <color name="white_opaque">#FFFFFFFF</color>
    <color name="pitch_black">#FF000000</color>

    <style name="AppTheme" parent="android:Theme.Light">
        <item name="android:background">@color/white_opaque</item>
        <item name="android:windowBackground">@color/white_opaque</item>
        <item name="android:colorBackground">@color/white_opaque</item>
    </style>

</resources>

and of course in the manifest

<application
    .
    .
    .
    android:theme="@style/AppTheme" > 
</application>

Android doc which I consulted on modifying themes: http://developer.android.com/guide/topics/ui/themes.html

I've tried switching between white_opaque and pitch_black for all the xml attributes but it doesn't change a thing. Any suggestions?

This question is related to android android-theme

The answer is


<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="android:Theme.Holo.NoActionBar">
        <item name="android:windowBackground">@android:color/black</item>
    </style>

</resources>

Open res -> values -> styles.xml and to your <style> add this line replacing with your image path <item name="android:windowBackground">@drawable/background</item>. Example:

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:windowBackground">@drawable/background</item>
    </style>

</resources>

There is a <item name ="android:colorBackground">@color/black</item> also, that will affect not only your main window background but all the component in your app. Read about customize theme here.

If you want version specific styles:

If a new version of Android adds theme attributes that you want to use, you can add them to your theme while still being compatible with old versions. All you need is another styles.xml file saved in a values directory that includes the resource version qualifier. For example:

res/values/styles.xml        # themes for all versions
res/values-v21/styles.xml    # themes for API level 21+ only

Because the styles in the values/styles.xml file are available for all versions, your themes in values-v21/styles.xml can inherit them. As such, you can avoid duplicating styles by beginning with a "base" theme and then extending it in your version-specific styles.

Read more here(doc in theme).