How can I change font size in PreferenceScreen

Finally I was able to solve my problem simply by passing one layout. Maybe this will be helpful to someone. This is my modified preference.xml see below code. We can apply our own properties to pref title and summary. preference.xml: <PreferenceScreen xmlns:android=”http://schemas.android.com/apk/res/android”> <PreferenceCategory android:title=”First Category” android:textSize=”20px” android:layout=”@layout/mylayout”> <CheckBoxPreference android:title=”Checkbox Preference” android:defaultValue=”false” android:summary=”This preference can be … Read more

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 listen for preference changes within a PreferenceFragment?

I believe you just need to register/unregister the Listener in your PreferenceFragment and it will work. @Override public void onResume() { super.onResume(); getPreferenceManager().getSharedPreferences().registerOnSharedPreferenceChangeListener(this); } @Override public void onPause() { getPreferenceManager().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this); super.onPause(); } Depending on what you want to do you may not need to use a listener. Changes to the preferences are committed to SharedPreferences … Read more

how to use getSharedPreferences in android

First get the instance of SharedPreferences using SharedPreferences userDetails = context.getSharedPreferences(“userdetails”, MODE_PRIVATE); Now to save the values in the SharedPreferences Editor edit = userDetails.edit(); edit.putString(“username”, username.getText().toString().trim()); edit.putString(“password”, password.getText().toString().trim()); edit.apply(); Above lines will write username and password to preference Now to to retrieve saved values from preference, you can follow below lines of code String userName … Read more

Android Alarm Clock UI

The stock alarm clock app is open source, so check it out by yourself. Preference Layout see here: <?xml version=”1.0″ encoding=”utf-8″?> <PreferenceScreen xmlns:android=”http://schemas.android.com/apk/res/android” android:title=”@string/set_alarm”> <CheckBoxPreference android:key=”on” android:title=”@string/enable”/> <Preference android:key=”time” android:title=”@string/time”/> <com.android.alarmclock.AlarmPreference android:key=”alarm” android:title=”@string/alert” android:ringtoneType=”alarm” android:showDefault=”false” android:showSilent=”false” /> <CheckBoxPreference android:key=”vibrate” android:title=”@string/alarm_vibrate”/> <com.android.alarmclock.RepeatPreference android:key=”setRepeat” android:title=”@string/alarm_repeat” /> <EditTextPreference android:key=”label” android:title=”@string/label” android:dialogTitle=”@string/label” /> </PreferenceScreen> Preference activity see here, note … Read more

Misbehavior when trying to store a string set using SharedPreferences

This “problem” is documented on SharedPreferences.getStringSet. The SharedPreferences.getStringSet returns a reference of the stored HashSet object inside the SharedPreferences. When you add elements to this object, they are added in fact inside the SharedPreferences. That is ok, but the problem comes when you try to store it: Android compares the modified HashSet that you are … 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