Categories
Android

Resetting the preferences on first launch of an app

If you want to reset or change preferences of an app at the first start here is an example of code you can put in an event as onCreate of the main activity:

Categories
Android

Padding and margin in DialogPreference

I implemented a Time Picker in the preference using the code found here where the class TimePreference extends the class DialogPreference but I found a lack of alignment with the other preference items because of a different setting of the margins and/or padding.

Categories
Android

How to display an icon in the preferences

In the Android preferences you can put different types of controls: check box, edit box, list,…, but none of these displays an icon (see Settings).
Usually a preference consists of two lines, the title and the summary, and after you have clicked you get a dialog box where you can select the chosen item, as you can see in the two pictures below.

Categories
Uncategorized

Preference element in xml and the click event

If you have an EditTextPreference tag in a xml file you can catch the click event implementing OnSharedPreferenceChangeListener but it doesn’t work if you have a Preference tag in the xml file.

Consider the following code inside a xml file for the preferences:

<Preference
	android:key="my_key"
	android:summary="my_summary"
 	android:title="my_title" >
</Preference>