Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Black screen in inner preferenceScreen

Tags:

android

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?

like image 822
rantravee Avatar asked Jul 02 '10 10:07

rantravee


3 Answers

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;
        }
    });
}
like image 116
Macarse Avatar answered Nov 07 '22 10:11

Macarse


What worked for me: Simply set a list style:

<style name="Theme.Preferences" parent="android:Theme.Light" >
    <item name="android:listViewStyle">@style/lightListView</item>
</style>
<style name="lightListView">
    <item name="android:background">#ffffff<item>
</style>
like image 4
M. Schenk Avatar answered Nov 07 '22 10:11

M. Schenk


Workaround:

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

2) Add secondary PreferenceScreen Activity to AndroidManifest.xml:

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

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

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

Example

like image 3
Shubin Yury Avatar answered Nov 07 '22 08:11

Shubin Yury