How to use the new API for the preferences presented in the new support library 23

Background

Google does not support backward compatibility. Preferences in the past were similar to Holo / Material, so I made my own library for this ( here , in case someone wants it), but now I think that Google provided some kind of support, here .

Problem

Currently I do not see any textbook or sample. I would like to know what features this new API has, but I cannot.

What i tried

I did as the instructions on the website said, and it even worked for Android GB, but this is what I got:

enter image description here

As you can see, the name of the category is the GB style, not the material design, and what you don’t see is that clicking on the elements will have the same effect as on GB. The same applies to some dialogue elements that are created in the settings. Almost everything is in the native style. The same thing happens with versions of Android 3.x-4.x.

Here is the code:

styles.xml

<style name="AppTheme" parent="Theme.AppCompat"> <!-- Customize your theme here. -->. <item name="windowActionBar">false</item> <item name="windowNoTitle">true</item> <item name="preferenceTheme">@style/PreferenceThemeOverlay</item> <item name="colorPrimary">#FF0288D1</item> </style> 

Mainactivity

 public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar _toolbar = (Toolbar) findViewById(R.id.activity_app_list__toolbar); // setSupportActionBar(_toolbar); getSupportFragmentManager().beginTransaction().replace(R.id.container, new SettingsFragment()).commit(); } } 

SettingsFragment.java

 public class SettingsFragment extends PreferenceFragmentCompat { @Override public void onCreatePreferences(Bundle bundle, String s) { addPreferencesFromResource(R.xml.preferences); } } 

preferences.xml

 <?xml version="1.0" encoding="utf-8"?> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <PreferenceCategory android:title="PreferenceCategory A"> <CheckBoxPreference android:key="checkbox_preference" android:title="title_checkbox_preference" android:summary="summary_checkbox_preference" /> </PreferenceCategory> <PreferenceCategory android:title="PreferenceCategory B"> <EditTextPreference android:key="edittext_preference" android:title="title_edittext_preference" android:summary="summary_edittext_preference" android:dialogTitle="dialog_title_edittext_preference" /> </PreferenceCategory> </PreferenceScreen> 

build.gradle

 ... compile 'com.android.support:appcompat-v7:23.0.1' compile 'com.android.support:preference-v7:23.0.1' 

Questions

  • Is there any tutorial / sample for the new API? Where can I find out more about this?

  • What specifically covers the new API?

  • Will it support material design style for all versions of Android? I tested it on the GB version, but it doesn't seem to work well ...

  • There seems to be a PreferenceFragmentCompat. Is it about the same as a PreferenceFragment? Will it work well even for pre-cell?

  • What are the missing features related to settings management?

  • How to set preferences and their dialogs with material style?

+5
source share

All Articles