Skip to content Skip to sidebar Skip to footer

Black Screen In Inner Preferencescreen

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

Solution 1:

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

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

    PreferenceScreenb= (PreferenceScreen) findPreference("pref_second_preferencescreen_key");
    b.setOnPreferenceClickListener(newOnPreferenceClickListener() {

        @OverridepublicbooleanonPreferenceClick(Preference preference) {
            PreferenceScreena= (PreferenceScreen) preference;
            a.getDialog().getWindow().setBackgroundDrawableResource(R.drawable.background);
            returnfalse;
        }
    });
}

Solution 2:

What worked for me: Simply set a list style:

<stylename="Theme.Preferences"parent="android:Theme.Light" ><itemname="android:listViewStyle">@style/lightListView</item></style><stylename="lightListView"><itemname="android:background">#ffffff<item></style>

Solution 3:

Workaround:

1) Prepare 2 PreferenceScreen xml's instead of sub PreferenceScreen using;

2) Add secondary PreferenceScreen Activity to AndroidManifest.xml:

<activityandroid:name="com.example.PreferenceActivity2"android:label="Issue4611"android:theme="@android:style/Theme.Light"><intent-filter><actionandroid:name="android.intent.action.VIEW"/><categoryandroid:name="android.intent.category.DEFAULT"/></intent-filter></activity>

3) For show secondary PreferenceScreen use in your first PreferenceScreen:

<PreferenceScreenandroid:key="key1"android:title="1 Item"android:summary=""><intentandroid:action="android.intent.action.VIEW"android:targetPackage="com.example"android:targetClass="com.example.PreferenceActivity2"/></PreferenceScreen>

Example

Solution 4:

Macarse's answer is perfect, I was searching for classic white background so I changed this line in his answer:

a.getDialog().getWindow().setBackgroundDrawableResource(R.drawable.background);

to:

a.getDialog().getWindow().setBackgroundDrawableResource(android.R.color.white);

and it works nicely.

Post a Comment for "Black Screen In Inner Preferencescreen"