PreferenceActivity is a professional setting interface. You only need to specify a configured xml for it, and it can automatically change the Preference value of the program according to the operation.
First, configure a setting interface with an xml file, that is, PreferenceScreen, and display it with PreferenceActivity. For example, create an xml folder under the res directory and create a new seeting. xml file.
The content is as follows:
CheckBoxPreference corresponds to a boolean value, and EditTextPreference corresponds to a String. Android: the key is the identifier and must be unique.
Each time you change the settings of the interface, the program automatically saves new values persistently.
It is also very easy to get the set value elsewhere in the program. You only need to use the identifier, for example, to get the values of the above identifiers as "boolean_value" and "string_value, you only need to use the following method.
BooleanValue =). getBoolean ("boolean_value", = PreferenceManager. getdefasharsharedpreferences ("string_value ","");
You can set common attributes in the following ways:
CheckBoxPreference CheckBox
EditTextPreference EditText
ListPreference List
RingtonePreference ringtones