问题
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