How to detect if changes were made in the preferences?

Do SharedPreferences.OnSharedPreferenceChangeListener spChanged = new SharedPreferences.OnSharedPreferenceChangeListener() { @Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { // your stuff here } }; In your PreferenceActivity, ie make it a member of your PreferenceActivity class and then do registerOnSharedPreferenceChangeListener(spChanged) in the PreferenceActivity.onCreate() method. That’s what I do and I never have a problem. Else it’s your conditional … Read more

Android: Unable to find explicit activity class… startActivity from a PreferenceActivity

I had this problem too. If you read carefully the error on the logcat, you will know what to do. You have to declare the activity in the AndroidManifest.xml <activity android:name=”.TheNameOfMyActivity” android:label=”@string/app_name” > <intent-filter> <category android:name=”android.intent.category.LAUNCHER” /> </intent-filter> </activity>

Custom PreferenceCategory Headings

You should take a look at Preference.Category style: <style name=”Preference.Category”> <item name=”android:layout”>@android:layout/preference_category</item> <item name=”android:shouldDisableView”>false</item> <item name=”android:selectable”>false</item> </style> Let’s take a look at preference_category.xml file: <!– Layout used for PreferenceCategory in a PreferenceActivity. –> <TextView xmlns:android=”http://schemas.android.com/apk/res/android” style=”?android:attr/listSeparatorTextViewStyle” android:id=”@+android:id/title” /> So you need to create custom theme that extends default android Theme and override listSeparatorTextViewStyle value with … Read more

How to add Action Bar from support library into PreferenceActivity?

EDIT: In appcompat-v7 22.1.0 Google added the AppCompatDelegate abstract class as a delegate you can use to extend AppCompat’s support to any activity. Use it like this: … import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatDelegate; import android.support.v7.widget.Toolbar; … public class SettingsActivity extends PreferenceActivity { private AppCompatDelegate mDelegate; @Override protected void onCreate(Bundle savedInstanceState) { getDelegate().installViewFactory(); getDelegate().onCreate(savedInstanceState); super.onCreate(savedInstanceState); } @Override … Read more

Android: Creating custom preference

The Android Developer page only shows how to make a DialogFragment. It’s still possible to customise the appearance of a Preference item though. In your XML you have to declare the root element as android:id=”@android:id/widget_frame, and then declare TextView as android:title and android:summary. You can then declare other elements you want to appear in the … Read more

No ActionBar in PreferenceActivity after upgrade to Support Library v21

Please find the GitHub Repo: Here Very Similar to your own code but added xml to allow for set title: Continuing to use PreferenceActivity: settings_toolbar.xml : <?xml version=”1.0″ encoding=”utf-8″?> <android.support.v7.widget.Toolbar xmlns:android=”http://schemas.android.com/apk/res/android” xmlns:app=”http://schemas.android.com/apk/res-auto” android:id=”@+id/toolbar” app:theme=”@style/ThemeOverlay.AppCompat.Dark.ActionBar” android:layout_width=”match_parent” android:layout_height=”wrap_content” android:minHeight=”?attr/actionBarSize” app:navigationContentDescription=”@string/abc_action_bar_up_description” android:background=”?attr/colorPrimary” app:navigationIcon=”?attr/homeAsUpIndicator” app:title=”@string/action_settings” /> SettingsActivity.java : public class SettingsActivity extends PreferenceActivity { @Override protected void onPostCreate(Bundle savedInstanceState) … Read more

How do I get the SharedPreferences from a PreferenceActivity in Android?

import android.preference.PreferenceManager; SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); // then you use prefs.getBoolean(“keystring”, true); Update According to Shared Preferences | Android Developer Tutorial (Part 13) by Sai Geetha M N, Many applications may provide a way to capture user preferences on the settings of a specific application or an activity. For supporting this, Android provides a simple … Read more