gpt4 book ai didi

java - DialogPreference 设置对话框的标题

转载 作者:行者123 更新时间:2023-11-30 09:20:57 25 4
gpt4 key购买 nike

我有一个 DialogPreference。我想设置它的对话框标题 (setTitle()),但它不起作用。

我的代码:

public class RestoreDefaultApperanceDialogPreference extends DialogPreference {

Dialog dialog;

public RestoreDefaultApperanceDialogPreference(Context context,
AttributeSet attrs) {
super(context, attrs);

dialog = getDialog();
//dialog.setTitle("Restore default colors?"); //<- NOT WORKING!
// TODO Auto-generated constructor stub
}

public RestoreDefaultApperanceDialogPreference(Context context,
AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
}
}

XML 文件(偏好类别):

<PreferenceCategory android:title="Appearance settings">
<com.example.dictionary.ColorSelectPreference
android:key="onlineRecognitionColor"
android:title="Online recognision results color"
android:summary="Customize color of online recognition results."
/>
<com.example.dictionary.ColorSelectPreference
android:key="offlineRecognitionColor"
android:title="Offline recognition results color"
android:summary="Customize color of offline recognition results."
/>
<com.example.dictionary.RestoreDefaultApperanceDialogPreference
android:key="restoreDefaultApperance"
android:title="Restore default apperance"
android:summary="Choose this option to restore default apperance settings."
/>
</PreferenceCategory>

如何为这个对话框设置标题

最佳答案

使用 setDialogTitle() 并覆盖 onDialogClosed() 来捕获按钮点击并执行您的操作。

public RestoreDefaultApperanceDialogPreference(Context context,
AttributeSet attrs) {
super(context, attrs);

setDialogTitle("Restore default colors?"); // <- this should work
}


@Override
protected void onDialogClosed(boolean positiveResult) {
super.onDialogClosed(positiveResult);

if (positiveResult) {
// OK button is pressed
} else {
// Cancel button is pressed
}
}

关于java - DialogPreference 设置对话框的标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17183160/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com