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

Android: Start Activity from preferences.xml

I was having the same issue. I got this working by only declaring the action in my AndroidManifest.xml, as such: <manifest xmlns:android=”http://schemas.android.com/apk/res/android” package=”com.example.myapp” android:versionName=”1.3″ android:versionCode=”4″> … <activity android:name=”.activities.MyActivity” android:label=”@string/my_activity_title” android:theme=”@android:style/Theme.Black.NoTitleBar”> <intent-filter> <action android:name=”com.example.myapp.activities.MyActivity” /> <category android:name=”android.intent.category.DEFAULT” /> </intent-filter> </activity> Then in my Preferences xml file: <PreferenceCategory android:title=”@string/my_activity_title”> <PreferenceScreen android:title=”@string/my_activity_title” android:summary=”@string/my_activity_title”> <intent android:action=”com.example.myapp.activities.MyActivity”/> </PreferenceScreen> </PreferenceCategory>

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

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 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

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

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)