127

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?

3

3 Answers 3

62

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.

1
  • 4
    Or you can just delete the other styles folders if you are not using them. I had the same problem and fixed it with one styles.xml, in the 'values' folder. My problem was that I had a theme item for the Activity in the manifest file (which of course overrode the AppTheme). Apr 10, 2013 at 9:00
58
<resources>

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

</resources>
19

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.