带有android.support.v4.app.Fragment的首选项片段 [英] Preference Fragment with android.support.v4.app.Fragment

查看:270
本文介绍了带有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.

如果确实需要使用support-v4库,我建议按照

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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆