Alternatives to PreferenceFragment with android-support-v4

后端 未结 9 2100
误落风尘
误落风尘 2020-11-28 04:50

I\'ve come to a sudden halt in the development of my app as I realized that PreferenceFragments weren\'t supported in this library. Are there any alternatives that a rookie

9条回答
  •  不知归路
    2020-11-28 04:59

    Preferences Support Library: Preference Fragments for API 7+, no matter the Activity

    A simple implementation would include a PreferenceFragmentCompat such as:

    public class PreferencesFragment extends PreferenceFragmentCompat {
        @Override
        public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
            addPreferencesFromResource(R.xml.preferences);
        }
    }
    

    You’ll also need to set preferenceTheme in your theme:

    
    

    And add this in dependencies: http://developer.android.com/tools/support-library/features.html

    com.android.support:preference-v14:23.1.0
    

提交回复
热议问题