Comments (6)
Here's a sample code, if anyone wants to check out:
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
SettingsActivity.java
public class SettingsActivity extends ActionBarActivity
{
public class SettingsFragment extends PreferenceFragment
{
@Override
public void onCreate(final Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.pref_general);
}
}
@Override
protected void onCreate(final Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getSupportFragmentManager().beginTransaction().add(R.id.container,new SettingsFragment()).commit();
}
}
pref_general.xml
<PreferenceCategory android:title="PreferenceCategory" >
<CheckBoxPreference
android:key="checkbox_preference"
android:summary="CheckBoxPreference"
android:title="CheckBoxPreference" />
</PreferenceCategory>
from android-support-v4-preferencefragment.
As someone not that familiar with fragments (I'm in the process of porting an old app from Action Bar Sherlock activities to ActionBarActivities with fragments), this was actually really helpful. Thanks.
from android-support-v4-preferencefragment.
@gstorer I've also made a library that doesn't require you to use a fragment for the preferences, if you wish:
https://github.com/AndroidDeveloperLB/MaterialStuffLibrary
from android-support-v4-preferencefragment.
I have a question:
This PreferenceFragment implementation can by used in a such scheme:
- as replacement for preHoneycomb PreferenceActivity enabling adding the same functionality inside ActionBarActivity (with ActionBar) like Preference Fragment -> Preference Screens, but without enabling usage of android PreferenceActivity -> Preference Headers + Preference Fragments -> Preference Screens
or - it could be used in conjunction with Android PreferenceActivity class postHoneycomb where this Activity provide preference header and associated Prefrence Fragments can be implemented with this android-support-v4-preferencefragment and it will provide preference screens... but if so what with Preference Activity on pre-honycomb, what I know there is only one Preference Activity class so on pre-honycomb it will not provider preference headers/action bard and so on ?
Please clarify scheme of use that works on pre-Honycomb and post-Honeycomb:
- it enables implementing only as this replacement for pre-Honycomb PreferenceActivity scheme
or - more sophisticated usage as post-Honeycomb with PreferenceActivity -> Preference Headers
from android-support-v4-preferencefragment.
@michzio Sadly, it's just the simple usage. no headers and such, as they weren't introduced on pre-Honeycomb, and the support library doesn't have those...
from android-support-v4-preferencefragment.
@michzio If you wish, you can check out my library that adds actionBar for PreferenceActivity:
https://github.com/AndroidDeveloperLB/ActionBarPreferenceActivity
A similar thing can be done here.
from android-support-v4-preferencefragment.
Related Issues (17)
- Not work with RingtonePreference HOT 9
- findPreference return null in api 10
- Push lib to Maven Central/jCenter HOT 25
- Big indents on Android L HOT 2
- NoClassDefFoundError R$layout HOT 1
- blank fragment HOT 9
- Plugin is too old HOT 1
- Can you add a license statement in your readme.md?
- This Handler class should be static or leaks might occur: Handler
- Listeners are not working? HOT 1
- cannot work with ListPreference
- Lov3
- Put it on Maven Central HOT 2
- Memory leak when using soft keyboard HOT 3
- Context menu items are the wrong color when using a app theme besides Theme.AppCompat HOT 1
- not working with Preference Headers HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from android-support-v4-preferencefragment.