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

爷,独闯天下 提交于 2019-12-11 01:35:51

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/35919798/preference-fragment-with-android-support-v4-app-fragment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!