Android PreferenceActivity

摘要:Android PreferenceActivity

PreferenceActivity 測試

實現結果:

 

Test.java

public class Test extends PreferenceActivity {

	@SuppressWarnings("deprecation")
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// add the xml resource 
		addPreferencesFromResource(R.xml.perference);
	}
}

 

perference.xml

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >

    <PreferenceCategory android:title="CheckBoxPreference" >
        <CheckBoxPreference
            android:key="checkbox_preference"
            android:title="Data" 
            android:summary="detail"/>
    </PreferenceCategory>

    <PreferenceCategory android:title="EditTextPreference" >
        <EditTextPreference
            android:dialogTitle="EditTextPreference"
            android:key="edittext_preference"
            android:title="Data"
            android:summary="detail" />
    </PreferenceCategory>
    
    <PreferenceCategory android:title="ListPreference" >
        <ListPreference
            android:dialogTitle="ListPreference"
            android:entries="@array/data"
            android:entryValues="@array/detail"
            android:key="list_preference"
            android:title="Data"
            android:summary="detail" />
    </PreferenceCategory>

    <PreferenceCategory android:title="NextScreenCheckBox" >
        <PreferenceScreen
            android:key="screen_preference"
            android:title="Data"
            android:summary="detail" >
            <CheckBoxPreference
                android:key="next_screen_checkbox_preference"
                android:title="Data"
                android:summary="detail" />
        </PreferenceScreen>
    </PreferenceCategory>
    
    <PreferenceCategory android:title="Intent" >
        <PreferenceScreen
            android:title="Data"
            android:summary="detail" >

            <intent
                android:action="android.intent.action.VIEW"
                android:data="http://www.android.com" />
        </PreferenceScreen>
    </PreferenceCategory>

    <PreferenceCategory android:title="preferenceLayoutChild" >
        <CheckBoxPreference
            android:key="parent_checkbox_preference"
            android:title="Data"
            android:summary="detail" />

        <CheckBoxPreference
            android:dependency="parent_checkbox_preference"
            android:key="child_checkbox_preference"
            android:layout="?android:attr/preferenceLayoutChild"
            android:title="Data"
            android:summary="detail" />
    </PreferenceCategory>

</PreferenceScreen>

 

array.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
     <string-array name="Data">
        <item>data 1</item>
        <item>data 2</item>
        <item>data 3</item>
    </string-array>
    
    <string-array name="Detail">
        <item>detail 1</item>
        <item>detail 2</item>
        <item>detail 3</item>
    </string-array>
    
</resources>