Boiler Plate Android EditTextPreference Implementation Example

Create a new directory from root of project (xml) and add a new xml file (other_prefs):

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen android:title="Other Preferences"
	android:key="Other_prefscreen" xmlns:android="">
	<EditTextPreference android:title="Carrier Caption"
		android:key="pref_lockscreen_caption" android:summary="The text to display at top of the lockscreen"
		android:defaultValue="Warm TwoPointThree" android:dialogTitle="Lockscreen caption" />

Create a new Activity under /src (

package com.roman.tweaks.activities;

import com.roman.tweaks.R;
import com.roman.tweaks.ShellInterface;

import android.os.Bundle;
import android.preference.EditTextPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceActivity;
import android.preference.PreferenceScreen;
import android.provider.Settings;

public class OtherActivity extends PreferenceActivity implements
		OnPreferenceChangeListener {

	public static final String TAG = "OtherActivity";

	// String keys for preference lookup
	private static final String PREF_CARRIER_CAPTION = "pref_lockscreen_caption";

	private EditTextPreference mLockscreenCaptionPref;

	protected void onCreate(Bundle savedInstanceState) {


		// get UI object references
		PreferenceScreen prefSet = getPreferenceScreen();

		mLockscreenCaptionPref = (EditTextPreference) prefSet


	public boolean onPreferenceChange(Preference preference, Object newValue) {

		if (preference == mLockscreenCaptionPref) {

			String inputCarrierText = String.valueOf((String) newValue);
					"tweaks_lockscreen_Caption", inputCarrierText);
			// Perform functions on preference change
			if (ShellInterface.isSuAvailable()) {
				ShellInterface.runCommand("echo '"+inputCarrierText+"' > /system/customize/lock_carrier.txt");
			return true;


		return false;


Used in Warm Tweaks. See


One thought on “Boiler Plate Android EditTextPreference Implementation Example

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s