简体   繁体   中英

Preference Fragment with android.support.v4.app.Fragment

How to use preference fragment with android.support.v4.app.Fragment? I tried to use android.preference.PreferenceFragment but I got an error: Wrong 2nd argument type/

FragmentTransaction transaction = getFragmentManager().beginTransaction();
            transaction.replace(R.id.fragment_container, new SettingsFragment());
            transaction.addToBackStack(null);
            transaction.commit();

SettingsFragment is the preference fragment

What can solve this problem?

By my knowledge PreferenceFragment is not supported in the android.support.v4 library.

You can however use PreferenceFragmentCompat from the support-v7 library.

If it really has to work with the support-v4 library, I would recommend adding the following project as a library project to your application as suggested by this old thread .

https://github.com/kolavar/android-support-v4-preferencefragment

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM