tags:

views:

225

answers:

1

My PreferenceActivity contains a nested PreferenceScreen in another PreferenceScreen and I'm applying a theme to my PrefenceActivity that changes the background color. However when I open the nested PreferenceScreen I get a black background and I cannot see the options.

This happens with android 2.1 , but it does not happen with android 1.6. Any ideas on how this can be corrected?

+1  A: 

I found a way to do it but it quite a hack.

This is my prefs.xml

<PreferenceCategory
    android:title="@string/hello">

    <CheckBoxPreference
        key="pref_update_key"
        android:title="@string/hello"
        android:summaryOn="@string/hello"
        android:summaryOff="@string/hello"
        android:persistent="true"
        android:defaultValue="false" />

</PreferenceCategory>

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:key="pref_second_preferencescreen_key" android:title="@string/hello">
        <CheckBoxPreference
        key="pref_update_key"
        android:title="@string/hello"
        android:summaryOn="@string/hello"
        android:summaryOff="@string/hello"
        android:persistent="true"
        android:defaultValue="false" />
</PreferenceScreen>

And this is my code for the class that extends PreferenceActivity

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.layout.prefs);
    getWindow().setBackgroundDrawableResource(R.drawable.background);

    PreferenceScreen b = (PreferenceScreen) findPreference("pref_second_preferencescreen_key");
    b.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            PreferenceScreen a = (PreferenceScreen) preference;
            a.getDialog().getWindow().setBackgroundDrawableResource(R.drawable.background);
            return false;
        }
    });
}
Macarse