我想出了我的自我。幹得好。
1包括在DialogPreference XML
<include layout="@layout/activity_header_template" />
的頁眉模板下面一行,並準備自己的自定義對話框佈局就像正常的自定義對話框模板。真正需要的是,我想自定義DialogPreference,我要爲密碼1和密碼2.兩個輸入(只是爲了確認密碼)
這是我ListPreference XML代碼
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="@string/preference_header_encryption">
<CheckBoxPreference
android:key="prefkey_use_passcode"
android:title="@string/preference_name_set_passcode"
android:summary="@string/preference_summary_set_passcode" />
<!-- This is how you need to attach CustomDialogPrefernce, by using the class name -->
<!-- Please ignore title here. Title will come from DialogPreference Constructor -->
<com.nerds.notes.SettPassword
android:key="prefkey_set_passcode"
android:summary="@string/preference_app_protection"
android:dialogMessage="@string/action_delete"
android:positiveButtonText="@string/passcode_ok_button_text"
android:negativeButtonText="@string/passcode_cancel_button_text"
android:dependency="prefkey_use_passcode" />
<CheckBoxPreference
android:key="prefkey_app_protection"
android:title="@string/preference_app_protection"
android:summary="@string/preference_summary_app_protection"
android:dependency="prefkey_use_passcode" />
</PreferenceCategory>
</PreferenceScreen>
以下行很重要的是,DialogPreference構造
public SettPassword(Context context, AttributeSet attrs) {
super(context, attrs);
setPersistent(false);
setTitle(R.string.preference_name_set_passcode); // This will override ListPreference Title
setDialogLayoutResource(R.layout.passcode_set_dialog_template);
}
以下行應在ListPreference onCreate方法進行編碼,具有自定義首選項文件名
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
PreferenceManager manager = getPreferenceManager();
manager.setSharedPreferencesName("Your Preference File Name");
manager.setSharedPreferencesMode(MODE_PRIVATE);
addPreferencesFromResource(R.xml.settings); // ListPreference XML file from XML Folder
}
我在這裏使用的一些方法是折舊 – Kirk