2010-07-02 22 views
10

Il mio PreferenceActivity contiene un nidificato PreferenceScreen in un altro PreferenceScreen e sto applicando un tema al mio PrefenceActivity che cambia il colore di sfondo. Tuttavia quando apro il nidificato PreferenceScreen ottengo uno sfondo nero e non riesco a vedere le opzioni.Schermo nero in preferenza internaScreen

Questo succede con Android 2.1, ma non succede con Android 1.6. Qualche idea su come questo può essere corretto?

+0

potresti fornire alcuni registri/altri dati? –

risposta

13

Ho trovato un modo per farlo ma è un bel compromesso.

Questo è il mio 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> 

E questo è il mio codice per la classe che 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; 
     } 
    }); 
} 
+1

non funziona per me provato su 1.6 e 2.3.4 entrambi mostrano ancora uno schermo nero. – schwiz

3

Soluzione:

1) Preparare 2 PreferenceScreen xml invece di sub PreferenceScreen utilizzando;

2) Aggiungere PREFERENCE attività secondaria a 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) Per l'esposizione utilizzo PREFERENCE secondaria nel vostro primo PREFERENCE:

<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

4

Quello che ha funzionato per me : Imposta semplicemente uno stile elenco:

risposta
+0

ha funzionato anche per me. Il problema con questo approccio si pone se si utilizza un background drawable personalizzato. – Shine

+0

Soluzione molto elegante! –

+1

Non dimenticare di modificare il tag dell'ultimo elemento finale su – WoodsLink

0

Macarse s' è perfetto, ero alla ricerca di sfondo bianco classico così ho cambiato questa linea nella sua risposta:

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

a:

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

e funziona bene .

+1

Non funziona per un secondo livello di schermata delle preferenze –

Problemi correlati