Android: Error inflating class PreferenceScreen

限于喜欢 提交于 2019-12-06 09:44:37

You need to remove the onCreateView function in your SignUpPreferenceFragment because you cannot inflate the preferences using the inflater.

That is why you are getting the error stating that there is an error inflating PreferenceScreen because it does not understand that tag/class in the xml.

The inflating of preferences.xml is done by addPreferencesFromResource in onCreate.

Reference

You must have a class where you inflate the preference.xml like this:

public static class SignUpPreferenceFragment extends PreferenceFragment {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Load the preferences from an XML resource
    addPreferencesFromResource(R.xml.preferences);
}

}

Add preference theme into your styles.xml

<item name="preferenceTheme">@style/PreferenceThemeOverlay</item>

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