Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PreferenceFragment does not show up in Activity

I have followed the guide "settings" from android developers. But when I launch my SettingsActivity all I get is white screen. What am I doing wrong?

Here is my SettingActivity.java

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 SettingFragment

public class SettingsFragment extends PreferenceFragment {

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

Here is preferences 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 that's how I switch to SettingsActivity

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

Is white screen is supposed to happed? I'm expecting a default screen with settings

like image 895
Oleg Filimonov Avatar asked Sep 05 '15 10:09

Oleg Filimonov


1 Answers

I found the solution.

The screen wasn't blank, my theme made all the text white on white background.

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

        android:theme="@style/SettingsTheme"
like image 151
Oleg Filimonov Avatar answered Nov 07 '22 17:11

Oleg Filimonov