1

I followed this probable solution but this only applies to root PreferenceScreen. I'm using v7 support PreferenceScreen and PreferenceFragmentCompat.

preference.xml

<android.support.v7.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
      <android.support.v7.preference.PreferenceScreen
            android:key="pref_key_r"
            android:persistent="false"
            android:summary="@string/a"
            android:title="@string/pref_title_r">
        </android.support.v7.preference.PreferenceScreen>
</android.support.v7.preference.PreferenceScreen>

SettingsFragment.java

    @Override
    public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
        addPreferencesFromResource(R.xml.preferences);
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        PreferenceScreen preferenceScreen = (PreferenceScreen) getPreferenceScreen().findPreference("pref_key_r");
        Preference preference = new Preference(preferenceScreen.getContext());

        preference.setKey("pref_key_sp");
        preference.setTitle(R.string.sp);
        preferenceScreen.addPreference(preference);

}

What am I still missing here?

Mr. Nacho
  • 315
  • 1
  • 3
  • 13

1 Answers1

1

It seems, that this is an unresolved issue from the preference design library as mentioned here.

There are some ugly workarounds to this problem mentioned in the link, but I'll personally just stick to the old android.preference.PreferenceFragment until this issue is resolved, because my preference screen relies on subscreens.

Edit: Here is another solution to this problem.

Antonio Dell
  • 497
  • 5
  • 17