Pantalla negra en la preferencia interna Pantalla

Mi PreferenceActivity contiene una PreferidaScreen anidada en otra PreferenceScreen y estoy aplicando un tema a mi PrefenceActivity que cambia el color de fondo. Sin embargo, cuando abro la ventana de PreferenceScreen anidadas, obtengo un fondo negro y no puedo ver las opciones.

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

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

Este 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 para 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; } }); } 

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

 <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> 

Solución:

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

2) Agregue la actividad PreferenceScreen 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 secundario de PreferenceScreen en su primera 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> 

Ejemplo

La respuesta de Macarse es perfecta, yo estaba buscando el fondo blanco clásico así 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.

FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.