WindowBackground does not change with theme

I have two themes in my application. I have a blue theme with a blue background:

<style name="Theme.BlueTheme" parent="Theme.Sherlock"> <item name="android:panelBackground">@drawable/menu_hardkey_panel_actionbar</item> <item name="android:buttonStyle">@style/ButtonAppTheme</item> <item name="android:windowBackground">@drawable/bground_blue</item> <item name="android:spinnerItemStyle">@style/SpinnerItem</item> <item name="android:editTextStyle">@style/Widget.EditText.White</item> <item name="android:spinnerItemStyle">@style/SpinnerItem</item> <item name="android:textViewStyle">@style/whitestyle</item> </style> 

I also have a white theme with a white background:

 <style name="Theme.AppTheme" parent="Theme.Sherlock.Light.DarkActionBar"> <item name="android:panelBackground">@drawable/menu_hardkey_panel_actionbar</item> <item name="android:buttonStyle">@style/ButtonAppTheme</item> <item name="android:windowBackground">@drawable/bground_white</item> <item name="android:spinnerItemStyle">@style/SpinnerItem</item> <item name="android:editTextStyle">@style/Widget.EditText.Black</item> </style> 

Everything works fine, except that the background is always white when I set the blue theme in the code.

In my manifest, my application theme is set to a white theme:

 <application android:allowBackup="true" android:icon="@drawable/launcher_icon" android:label="@string/app_name" android:theme="@style/Theme.AppTheme" > 

Then I set the blue theme to my ActivityBase class in onCreate:

 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setDisplayHomeAsUpEnabled(true); } setTheme(R.style.Theme_BlueTheme); } 
+6
source share
1 answer

You must set Theme before calling super.onCreate () and setContentView ().

+10
source

All Articles