Profile cover photo
Profile photo
Lavakush Verma
284 followers
284 followers
About
Communities and Collections
View all
Posts

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 (http://goo.gl/BPE0M1) makes it possible to use any Activity class (such as an AppCompatActivity) with PreferenceFragmentCompat (http://goo.gl/kKXszC) and add preferences using the same preference XML files (http://goo.gl/wOcIxI), 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 {
 @Override
  public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
    addPreferencesFromResource(R.xml.preferences);
  }
}

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>
</style>

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 (http://goo.gl/119brU) with the help of the Android Design Support Library (http://goo.gl/8LN2Aj).

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 (http://goo.gl/IZWZBP) to handle preferences with an app:fragment attribute or OnPreferenceStartScreenCallback (http://goo.gl/CFp5Cr) 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 (http://goo.gl/i2A1zF) incredibly helpful - providing an optimized Leanback version of preferences via LeanbackPreferenceFragment (http://goo.gl/eLqNEv) built on top of these preference APIs.

#BuildBetterApps
Add a comment...

Post has attachment
Add a comment...

Post has shared content
Great evolution summary of a variety of #userInterfaces through enhancements of hardware & software. :) http://bit.ly/1FAdPa8 #UI #UX #IxD
Add a comment...

Post has attachment
Add a comment...

Post has attachment
Add a comment...

Post has attachment
Add a comment...

Post has attachment

Post has attachment
Good App with most used features on your thumb...
Add a comment...

Post has attachment
 UP 72825 Teachers Merit List

If you face any issues with 164.100.181.130 -As Site may be down to respond Right Now? Please go through this link to download the Provisional Rank List.

Note: All the files have been downloaded from http://164.100.181.141/ and no modifications has been made.

https://drive.google.com/folderview?id=0B91lHnERG1M1ZjBZQkdaZkVjYjA&usp=sharing
Add a comment...
Wait while more posts are being loaded