PreferenceFragment not showing in Activity

I followed the β€œsettings” of the guide from the Android developers. But when I start my SettingsActivity, I get a white screen . What am I doing wrong?

Here is my SettingActivity.java parameter

public class SettingsActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getFragmentManager().beginTransaction() .replace(android.R.id.content, new SettingsFragment()) .commit(); } } 

Here is the SettingFragment parameter

 public class SettingsFragment extends PreferenceFragment { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); } } 

Here is the settings file

 <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <EditTextPreference android:title="Your Name" android:key="username" android:summary="Please provide your username"></EditTextPreference> <CheckBoxPreference android:title="Application Updates" android:defaultValue="false" android:summary="This option if selected will allow the application to check for latest versions." android:key="applicationUpdates" /> <ListPreference android:title="Download Details" android:summary="Select the kind of data that you would like to download" android:key="downloadType" android:defaultValue="1" android:entries="@array/listArray" android:entryValues="@array/listValues" /> </PreferenceScreen> 

And how do I switch to SettingsActivity

 Intent intent = new Intent(MainActivity.this, SettingsActivity.class); startActivity(intent); 

Is a white screen expected? I expect a default screen with settings

+6
source share
1 answer

I have found a solution.

The screen was not blank, my theme made all the text white on a white background.

So, I just added a custom theme for the settings activity and added this to the android manifest:

  android:theme="@style/SettingsTheme" 
+2
source

All Articles