0

我创建了一个带有 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>
4

2 回答 2

0

我通过使用普通 Activity 而不是 PreferenceActivity 解决了它。

于 2013-12-23T09:29:06.937 回答
-1

您不是使用 SharedPreferences 类为首选项添加的代码
我已经添加了一个使用您的复选框首选项示例检查下面的代码

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

//xml 首选项.xml

<PreferenceCategory
        android:title="PreferenceCategory A">

    <CheckBoxPreference
            android:key="checkbox_preference"
            android:title="title_checkbox_preference"
            android:summary="summary_checkbox_preference" />

</PreferenceCategory>

<PreferenceCategory
        android:title="PreferenceCategory B">

    <EditTextPreference
            android:key="edittext_preference"
            android:title="title_edittext_preference"
            android:summary="summary_edittext_preference"
            android:dialogTitle="dialog_title_edittext_preference" />

</PreferenceCategory>

于 2013-12-20T14:57:58.350 回答