我是安卓新手。我的首选项屏幕选项未显示。我正在关注下面的教程部分“首选项”和“创建设置活动”(https://wiki.oulu.fi/display/esde/List+views%2C+Intents%2C+Preferences+and+Notifications)
这是我的 SettingsActivity.java 类
public class SettingsActivity extends Activity {
public static class SettingsFragment extends PreferenceFragment {
private SettingsFragment settingsFragment = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Load the preferences from an XML resource
addPreferencesFromResource(R.xml.preferences);
settingsFragment = new SettingsFragment();
// Display the fragment as the main content.
getFragmentManager().beginTransaction()
.replace(android.R.id.content, settingsFragment)
.commit();
}
}
这是首选项的设置
<?xml version="1.0" encoding="utf-8"?>
<PreferenceCategory android:title="@string/server_settings" >
</PreferenceCategory>
<CheckBoxPreference
android:defaultValue="false"
android:key="@+id/pref_check"
android:summaryOff="@string/pref_off"
android:summaryOn="@string/pref_on" >
</CheckBoxPreference>
<EditTextPreference
android:key="@+id/pref_edit"
android:defaultValue="@string/pref_default"
android:dialogTitle="@string/edit_text_pref">
</EditTextPreference>
在主要活动中,我有以下启动 SettingActivity 类的方法。
// launch the settings activity
public boolean onOptionsItemSelected(MenuItem item) {
startActivity(new Intent(this, SettingsActivity.class));
//return super.onOptionsItemSelected(item);
return true;
}
我还在主要活动下添加了以下代码,onCreate 方法从首选项设置文件中初始化设置的默认值
PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
你能帮我解决这个问题吗?