Questions tagged [preferencefragment]

A specialized Android fragment used to show a Preference Screen

Shows a hierarchy of Preference objects as lists. These preferences will automatically save to SharedPreferences as the user interacts with them. To retrieve an instance of SharedPreferences that the preference hierarchy in this fragment will use, call getDefaultSharedPreferences(android.content.Context) with a context in the same package as this fragment.

Furthermore, the preferences shown will follow the visual style of system preferences. It is easy to create a hierarchy of preferences (that can be shown on multiple screens) via XML. For these reasons, it is recommended to use this fragment (as a superclass) to deal with preferences in applications.

A PreferenceScreen object should be at the top of the preference hierarchy. Furthermore, subsequent PreferenceScreen in the hierarchy denote a screen break--that is the preferences contained within subsequent PreferenceScreen should be shown on another screen. The preference framework handles showing these other screens from the preference hierarchy.

Unfortunately, it's not actually part of the support library.
So, any device running an API Level prior to 11, has to use the good old PreferenceActivity.

Reference page: http://developer.android.com/reference/android/preference/PreferenceFragment.html

243 questions
115
votes
13 answers

PreferenceFragmentCompat requires preferenceTheme to be set

With the new PreferenceFragmentCompat from the v7 Preference Support Library: http://developer.android.com/tools/support-library/features.html#v7-preference, I get this error E java.lang.IllegalStateException: Must specify preferenceTheme in…
38
votes
7 answers

PreferenceFragmentCompat has padding on PreferenceCategory that I can't get rid of

So I've been trying to create a settings activity using androidx.preference.PreferenceFragmentCompat and it's all working fine. However for some reason there is some padding present on both the preference categories and the preferences themselves. I…
28
votes
2 answers

Installing a support library for PreferenceFragmentCompat

I'm new to Android Studio and a total beginner at Android programming in general. I looked and looked and I couldn't find the right thing to do. All I want is to install a library to use PreferenceFragmentCompat or any class that replaces…
siriuseteor77
  • 1,004
  • 2
  • 12
  • 30
21
votes
3 answers

PreferenceFragmentCompat custom layout

I need a custom layout for my PreferenceFragmentCompat. In the docs for PreferenceFragmentCompat it seems that you can possibly inflate and return a view in onCreateView(). However a NPE results:- Caused by: java.lang.NullPointerException: Attempt…
18
votes
8 answers

Keep the actionbar displayed in when changing PreferenceScreen

I'm trying to display a actionbar in my preference screen. In order to do so I added the following code in my SettingActivity public class PreferencesActivity extends ActionBarActivity { @Override protected void onCreate(Bundle…
17
votes
4 answers

Toolbar is hidden in nested PreferenceScreen

I use PreferenceFragment in ActionBarActivity from support-v7 library. In the Activity I have Toolbar. Everything goes okay, until I open a nested PreferenceScreen. In the opened screen the Toolbar is hidden. Maybe somebody know a workaround for…
16
votes
2 answers

PreferenceFragment crashing, Null object Reference

I have a simple ActionBarActivity which holds a PreferenceFragment as follows: import android.app.Activity; import android.os.Bundle; import android.preference.PreferenceFragment; public class SettingsActivity extends Activity { …
Ryan
  • 762
  • 8
  • 17
12
votes
3 answers

androidx.preference.PreferenceScreen not found when creating Preferences screen

After following this tutorial to create a screen for preferences, there seems to be a problem with inflating the class 'androidx.preference.PreferenceScreen'. Why is it not found when my preferences have been declared inside the res/xml folder and…
wbk727
  • 8,017
  • 12
  • 61
  • 125
12
votes
3 answers

Show up-Button in actionBar in subscreen preferences

I've implemented my preferences like shown in the official guidelines. I have a PreferenceActivity which creates the PreferenceFragment like this: @Override protected void onCreate(Bundle savedInstanceState) { …
9
votes
1 answer

Preferences library is causing E/libc & E/Pref errors

I'm building a weather app using MVVM and retrofit and i recently added a PreferencesFragmentCompat subclass to implement some user settings using the preferences lib. After doing so, my app won't run and i keep getting these few lines of errors…
9
votes
3 answers

How to open a new PreferenceFragment from current one, using the new Android-X API?

Background On previous versions of support library, we could use headers in order to have a main-menu screen of settings, that each would open a new settings screen (fragment) . The problem Now headers are gone (as written here) for some time, and…
9
votes
5 answers

How to add a Progress Bar in a PreferenceFragment in Android?

How can I add a progress bar in a PreferenceFragment? I have some async task running that will display some values in my preference upon completion. So while it is doing the background process, I plan to show only a progress bar in the center. After…
ads
  • 1,703
  • 2
  • 18
  • 35
9
votes
2 answers

Is there a way to style PreferenceFragmentCompat

The title says it all: how can I style my PreferenceFragmentCompat. My v14/style.xml is