PreferenceFragment 未按预期添加到 Activity

PreferenceFragment is not added to Activity as expected

我正在尝试根据 Google 文档中的 API 复制和粘贴来实现 PreferenceFragment

现在 here 它说:

You can then add this fragment to an Activity just as you would for any other Fragment.

但是,在这一行有一个编译时错误:

    // Display the fragment as the main content.
    getFragmentManager().beginTransaction()
            .replace(android.R.id.content, new SettingsFragment())
            .commit();

说:

replace (int, android.support.v4.Fragment) in FragmentTransaction cannot be aplied to (int, PrefsFragment)

我的 class PrefsFragment 扩展了 PreferenceFragment。

我做错了什么?

目前 `PreferenceFragment' 不是 Android 中支持库的一部分,这就是为什么您不能在那里使用它的原因,我找到了一个解决该问题的库。你可以找到它here只需将它添加到你的项目中就可以了