I'm looking to write preferences that can be applied to both 3.0 and pre-3.0 devices. Discovering that PreferenceActivity
contains deprecated methods (although these are used in the accompanying sample code), I looked at PreferenceFragement
and the compatibility package to solve my woes.
It appears, though, that PreferenceFragment
isn't in the compatibility package. Can anyone tell me whether this was intentional? If so, can I easily target a range of devices (i.e. < 3.0 and >=3.0) or will I have to jump through hoops? If it wasn't intentionally excluded, can we expect a new release of the compatibility package? Or is there another workaround that is safe to use?
Cheers
James
On August 2015 Google released the new Preference Support Library v7.
Now you can use the PreferenceFragmentCompat with any
Activity
orAppCompatActivity
You have to set
preferenceTheme
in your theme:In this way you can customize the
preferenceTheme
to style the layouts used for each preference type without affecting other parts of your Activity.The deprecated methods are deprecated as of Android 3.0. They are perfectly fine on all versions of Android, but the direction is to use
PreferenceFragment
on Android 3.0 and higher.My guess is it's a question of engineering time, but that's just a guess.
I consider it to be done "easily". Have two separate
PreferenceActivity
implementations, one using preference headers andPreferenceFragments
, the other using the original approach. Choose the right one at the point you need to (e.g., when the user clicks on the options menu item). Here is a sample project demonstrating this. Or, have a singlePreferenceActivity
that handles both cases, as in this sample project.You will find out when the rest of us find out, which is to say, if and when it ships.
See above.