0
votes

in my app I let the user choose which theme he wants to use (dark or light). The themes are defined in my styles.xml as followed:

<style 
    name="but" 
    parent="android:style/Widget.Holo.ActionButton">
</style>
<style
    name="bar"
    parent="android:style/Widget.Holo.ActionBar.Solid">
</style>

<style 
    name="Theme_Flo" 
    parent="android:Theme.Holo">

    <item name="android:buttonStyle">@style/but</item>
    <item name="android:actionBarStyle">@style/bar</item>

</style>
<style 
    name="Theme_Flo_Light"
    parent="android:Theme.Holo.Light.DarkActionBar">

    <item name="android:buttonStyle">@style/but</item>
    <item name="android:actionBarStyle">@style/bar</item>

</style>

The dark theme is applied everywhere correctly.

The light theme is ok except for the text color of the actionbar (it's black instead of white) and my preferenceactivity, which consists of a main preferencescreen and some inner preferencescreens. The inner screens have the correct theme (except for the actionbar text color). But the outer preferencescreen (main screen) has a dark background with dark text color. So I guess the text color is choosen correctly, but the background color not. Setting the background color in my settings.xml via android:background has no effect. I've found several posts about black screen in inner preferencescreens but not this way.

The themes are applied in the onCreate method like this:

public class SettingsApp extends PreferenceActivity implements OnSharedPreferenceChangeListener, OnPreferenceChangeListener {
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if(TimeMateActivity.theme.equals("0")) {
            setTheme(R.style.Theme_Flo);
        }else{
            setTheme(R.style.Theme_Flo_Light);
        }
    addPreferencesFromResource(R.layout.settings);

    ActionBar actionBar = getActionBar();
        actionBar.setDisplayHomeAsUpEnabled(true);

        ...
    }
}

I have checked that the correct theme is choosen.

Target and Min Api version is 17, if this is important.

Can anybody help me here?

1

1 Answers

1
votes

Move the setTheme before super.onCreate(savedInstanceState); so your code looks like this:

public class SettingsApp extends PreferenceActivity implements OnSharedPreferenceChangeListener, OnPreferenceChangeListener {

 public void onCreate(Bundle savedInstanceState) {
   if (TimeMateActivity.theme.equals("0")) {
      setTheme(R.style.Theme_Flo);
   } else {
      setTheme(R.style.Theme_Flo_Light);
   }
   super.onCreate(savedInstanceState);
   addPreferencesFromResource(R.layout.settings);

   ActionBar actionBar = getActionBar();
   actionBar.setDisplayHomeAsUpEnabled(true);
   ...
 }
}