Android Lollipop preference - android

Is there an easy way to create a preference like the system preferences in Lollipop?
My previous app had headers and fragments, but I want to use the AppCompat Toolbar and the PreferenceActivity (onBuildHeaders) can't use the new Toolbar. That's why I'm searching for a complete redesign of my preferences.
I want to do this:
Has someone any tutorial for this?

It' s simple. Just apply the Theme.AppCompat.xxx to your activity and put your PreferenceFragment in that activity if you use the Api level >= 11.
EDIT
for the lastest supoort libary appcompat-v7, google provides AppCompatDelegate to do the trick, here is the sample code from google.

Try out my library: https://github.com/AndroidDeveloperLB/MaterialPreferenceLibrary .
It lacks some of the stuff of the original API, but it's a good start... The hard part is to make it use a RecyclerView instead of a ListView, so that you could have multiple preferences on the same row. Then you'd need to also filter items as you type.

Related

AndroidX: howto create preference grouping?

I used to have a PreferenceActivity in Android but then I wanted to migrate to AndroidX.
Now I can't find any solution to have this kind of preference grouping:
I have tried:
PreferenceCategory (but it doesn't groups preferences into deeper levels, just visually breaks them)
PreferenceScreen (before AndroidX it used to work, but now it just display the main settings /General, Notifications, Data & Sync/ but I cannot go deeper.)
PreferenceGroup (but it is abstract and I have no idea how shall I implement, or shall it work at all)
Do you have any idea on how can I get the above functionality with AndroidX Preference library?
(androidx.preference:preference:1.1.0).
You should use a separate PreferenceFragmentCompat per sub-screen, see the Settings Guide for more information.

Best practice to bring Material look to Preferences using AppCompat?

What is the best way to bring Material design to the preferences using AppCompat?
I've been reading some questions and the main points seem to be:
The official guidelines suggest avoiding PreferenceActivity if working for API>11 (and I am). Instead one should use PreferenceFragments;
Using PreferenceActivity would be bad also because you can't extend both PreferenceActivity and ActionBarActivity;
You might use a general ActionBarActivity and load PreferenceFragment (API>11) into it. This way preference widgets loaded from resources gets tinted by AppCompat, but that's not true for any widget (see here );
With the suggested solution, anyway, the whole UI look isn't quite Material (see image on Android 4.2), even if inheriting from AppCompat theme.
Another way could be to extend a PreferenceActivity (API>1). As said, you won't extend ActionBarActivity but just inherit AppCompat theme.
Last, you could just make your own Activity extending ActionBarActivity, and deal with widgets, layouts, margins, SharedPreferences yourself.
At the moment I am not aware of a working solution. I've seen some discussion going on in a Chris Banes post introducing Material, but no solution was suggested. I'm asking:
Did some of you succeed in bringing a pure (as possible) Material look to preferences, and how?
Will there be improvements in v7 regarding this issue in the future?
I'm using AndroidDeveloperLB/MaterialPreferenceLibrary in my projects.
Easy to install. ImportEasy to use. Sample

PreferenceActivity getSupportLoaderManager()

I use ActionBarSherlock in my app.
What I would like to do is to use CursorLoader in PreferenceActivity. It's possible, but as far as I can see, only on API level >= 11.
I thought that maybe SherlockPreferenceActivity would solve it, but it doesn't have getSupportFragmentManager() either. (tagging it as actionbarsherlock because, maybe I missed something)
Is there any way to use standard preference activity with loader and support older platforms or should I just build a custom preference screen?

android compatibility API alternatives to PreferenceFragment

I want to display a main menu on the left and a settings page on the right of the screen. I want to use the Android compatibility API and fragments.
I also want to make use of the Android preferences features and add the preferences from .xml file, and don't want to use workarounds (like personally customized list views, linear layouts, etc). What options do I have, considering that PreferenceFragment is not included in the compatibility API?
Try using ActionBarSherlock's PreferenceActivity plugin.
Here is the sample source code.

Customizing a project library in Android

I'm using this library project in my Android application. But I need to make some customization for it.
For example, if I need a EditText instead of the provided TextView, what is the best practice to customize the library for my needs without writing code in the Project Library?
I made this customization by defining in the library's actionbar.xml layout a EditText instead of TextView, but I don't like this approach.
Do you have any guidelines, tutorials that could help me out?
In your special case I would suggest to use original compatibility's-package actionBar.
But to answer your question: you could always extend classes from the Library, which I think is the best practice if the library should kept untouched. Overriding Methods which you want to change their behavior keeps anything clean. You do the exact same every time you extend android-sdk classes, which you cannot change like you want.
In the case of changing layouts I'm not quite shure. I think I can remember that if the lib has an actionbar.xml and you have an actionbar.xml inside your project, too, yours will win. just like an "overriding layouts" feature

Categories

Resources