我创建了一个带有 PreferenceFragment 的 PreferenceActivity。但是所有设置的内容都显示在布局边界之外,我做错了什么?
设置活动:
public class SettingsActivity extends PreferenceActivity {
@Override
protected void onCreate(final Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
getFragmentManager().beginTransaction().replace(android.R.id.content, new MyPreferenceFragment()).commit();
}
public static class MyPreferenceFragment extends PreferenceFragment
{
@Override
public void onCreate(final Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
}
}
}
首选项.xml:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="My list of Preferences">
<CheckBoxPreference android:title="Checkbox Preference"
android:defaultValue="false" android:summary="This preference can be true or false"
android:key="checkboxPref" />
<EditTextPreference android:name="EditText Preference"
android:summary="This allows you to enter a string"
android:defaultValue="Nothing" android:title="Edit This Text"
android:key="editTextPref" />
<RingtonePreference android:name="Ringtone Preference"
android:summary="Select a ringtone" android:title="Ringtones"
android:key="ringtonePref" />
<PreferenceScreen android:key="SecondPrefScreen"
android:title="Secondary Level" android:summary="This is a sub PreferenceScreen">
<intent android:action="android.intent.action.VIEW"
android:targetPackage="com.as400samplecode" android:targetClass="com.as400samplecode.Preferences2" />
</PreferenceScreen>
<Preference android:title="Custom Preference"
android:summary="This works almost like a button" android:key="customPref" />
</PreferenceCategory>
</PreferenceScreen>