Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 the background is always the white one when I set the blue theme in code.

My application theme is set to the white theme in my manifest:

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

I then set the blue theme up in 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);
}
like image 466
Tjaart Avatar asked Feb 12 '13 08:02

Tjaart


1 Answers

You have to setTheme before you call super.onCreate() and setContentView().

like image 195
Michał Z. Avatar answered Sep 20 '22 09:09

Michał Z.