带有android.support.v4.app.Fragment的首选项片段 [英] Preference Fragment with android.support.v4.app.Fragment
问题描述
如何将首选项片段与android.support.v4.app.Fragment一起使用? 我尝试使用android.preference.PreferenceFragment但出现错误:错误的第二个参数类型/
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是首选项片段
SettingsFragment is the preference fragment
什么可以解决这个问题?
What can solve this problem?
推荐答案
据我所知,android.support.v4
库中不支持PreferenceFragment
.
By my knowledge PreferenceFragment
is not supported in the android.support.v4
library.
但是,您可以使用support-v7库中的PreferenceFragmentCompat
.
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
这篇关于带有android.support.v4.app.Fragment的首选项片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!