我会尽力协助您完成翻译。以下是您需要翻译的内容:
我自己解决了,这是解决方案:
首先,在DialogPreference XML文件的Header Template中添加以下行:
<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" />
<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);
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);
}