Profile cover photo
Profile photo
Carmelo Ruota

Post has attachment
Add a comment...

Post has shared content
Preferences Support Library: Preference Fragments for API 7+, no matter the Activity
Pro-tip by +Ian Lake

Creating your preferences from XML files means less code and a consistent user experience across apps. However, this required that you use PreferenceActivity and even then you could only use PreferenceFragment on API 11+ devices. Well, no more: the Preferences Support v7 Library ( makes it possible to use any Activity class (such as an AppCompatActivity) with PreferenceFragmentCompat ( and add preferences using the same preference XML files (, while adding support for elements such as SwitchPreference (previously only available on API 14+ devices) to all API 7+ devices.

A simple implementation would include a PreferenceFragmentCompat such as:
public class PreferencesFragment extends PreferenceFragmentCompat {
  public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {

You’ll also need to set preferenceTheme in your theme:
<style name="AppTheme" parent="@style/Theme.AppCompat.Light">
  <!-- Set colorPrimary, colorPrimaryDark, colorAccent, etc →
  <item name="preferenceTheme">@style/PreferenceThemeOverlay</item>

Customizing the preferenceTheme allows for increased control over the styling and layouts used for each preference type without affecting other parts of your Activity.

Even better, PreferenceFragmentCompat uses RecyclerView for showing the list of preferences, allowing you to integrate scrolling techniques ( with the help of the Android Design Support Library (

One thing you’ll note isn’t in here is preference headers and you’d be totally right. However, that doesn’t mean a single list of preferences need to span a 10” tablet screen. Instead, your Activity can implement OnPreferenceStartFragmentCallback ( to handle preferences with an app:fragment attribute or OnPreferenceStartScreenCallback ( to handle PreferenceScreen preferences. This allows you to construct a ‘header’ style PreferenceFragmentCompat in one pane and use those callbacks to replace a second pane without working in two separate types of XML files.

So what about the preferences-v14 library? You’ll find it offers the same API as the preferences-v7 library, but built on framework Fragments and DialogFragments.

If you’re building apps for Android TV, you’ll find the preference-v17 library ( incredibly helpful - providing an optimized Leanback version of preferences via LeanbackPreferenceFragment ( built on top of these preference APIs.

Add a comment...

#MVP  or #MVVM ? This is the problem.
Add a comment...

Post has shared content
Ecco il nuovo numero di Wired Italia​, dedicato alle 100 serie tv più Wired della storia, da guardarvi e riguardarvi questa estate.

Il numero (da oggi nelle edicole milanesi, nei prossimi giorni nel resto d'Italia) è doppio: starà in edicola a luglio e agosto.
Add a comment...

Fix tracking #Nexive

Integrato corriere

Anche quest'anno #DroidconIT  :-) Qualcuno ci va?

Aggiunto #UPU  per corrieri orientali 

Wait while more posts are being loaded