2010-07-02 17 views
10

Mi PreferenceActivity contiene un PreferenceScreen anidado en otro PreferenceScreen y estoy aplicando un tema a mi PrefenceActivity que cambia el color de fondo. Sin embargo, cuando abro el PreferenceScreen anidado obtengo un fondo negro y no puedo ver las opciones.Pantalla negra en la preferencia interiorScreen

Esto ocurre con Android 2.1, pero no sucede con Android 1.6. ¿Alguna idea sobre cómo se puede corregir esto?

+0

¿podría proporcionarnos algunos registros/más datos? –

Respuesta

13

Encontré una manera de hacerlo, pero fue un hack.

Esta es mi 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> 

y este es mi código de la clase que 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

no funciona para mí probado en 1.6 y 2.3.4 ambos muestran una pantalla negra. – schwiz

3

Solución:

1) Prepare 2 PreferenceScreen xml en lugar de sub PreferenceScreen usando;

2) Añadir Actividad PREFERENCE secundaria 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) Para mostrar el uso PREFERENCE secundaria en su primera 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

Lo que funcionó para mí : Simplemente configure un estilo de lista:

respuesta
+0

funcionó para mí, también. El problema con este enfoque surge si utiliza un fondo dibujable personalizado. – Shine

+0

¡Solución muy elegante! –

+1

No olvide cambiar la etiqueta del último elemento al – WoodsLink

0

Macarse 's es perfecto, que estaba buscando para el fondo blanco clásico por lo que cambió esta línea en su respuesta:

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

a:

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

y funciona muy bien .

+1

No funciona para un segundo nivel de pantalla de preferencias –

Cuestiones relacionadas