Setting Android Theme background color

AndroidAndroid Theme

Android Problem Overview


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?

Android Solutions


Solution 1 - Android

Okay turned out that I made a really silly mistake. The device I am using for testing is running Android 4.0.4, API level 15.

The styles.xml file that I was editing is in the default values folder. I edited the styles.xml in values-v14 folder and it works all fine now.

Solution 2 - Android

<resources>

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

</resources>

Solution 3 - Android

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionStarkView Question on Stackoverflow
Solution 1 - AndroidStarkView Answer on Stackoverflow
Solution 2 - AndroidOded BreinerView Answer on Stackoverflow
Solution 3 - AndroidBlasankaView Answer on Stackoverflow