5

Background

Google hasn't supported backward-compatibility Preferences to look like Holo/Material in the past, which is why I've made my own library for this (here, in case anyone wants it), but now I think that Google has provided some sort of support for it, here.

The problem

For now, I can't see any tutorial or sample. I'd like to know what features this new API has, but I can't.

What I've tried

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

enter image description here

As you can see, the category title is GB style instead of material design, and what you can't see is that clicking on items will have the same effect as on GB. Same goes to some elements of dialogs that are created in the preferences. Almost everything is in the native style. The same thing occurs on 3.x-4.x versions of Android.

Here's 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'

The questions

  1. Is there any tutorial/sample for the new API? Where can I read more about it?

  2. What does the new API cover exactly ?

  3. Will it support Material design style for all Android versions? I've tested it on GB version, but it doesn't seem to work well...

  4. It seems there is PreferenceFragmentCompat. Is it about the same as PreferenceFragment ? Will it work well even for pre-Honeycomb ?

  5. What missing features are there, that are related to preferences management?

  6. How do I make the preferences and their dialogs have material style?

android developer
  • 114,585
  • 152
  • 739
  • 1,270

0 Answers0