我有一个警告对话框,目前看起来像这样:当前警告对话框
但我希望"Yes"和"No"按钮有背景,或者看起来像按钮而不仅仅是文本。我尝试实现AlertDialog的自定义主题,但我能够做出的唯一改变是改变“WARNING”文字颜色。
最有效和简单的方法是什么,以定制警告对话框的主题,以便在"Yes"和"No"的位置上有实际的按钮?
这是我的当前res/values/styles.xml文件。
任何建议都受到赞赏。我是Android新手。
最有效和简单的方法是什么,以定制警告对话框的主题,以便在"Yes"和"No"的位置上有实际的按钮?
这是我的当前res/values/styles.xml文件。
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- Customize your theme here. -->
<item name="colorAccent">@color/PCCA_blue</item>
</style>
<style name="customAlertDialog" parent="@android:style/Theme.Holo.Dialog">
<item name="android:textColor">@color/red</item>
</style>
这是我构建并显示AlertDialog的位置:
private void alert(final String action){
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(new ContextThemeWrapper(this, R.style.customAlertDialog));
String message = "";
switch(action) {
case "upload":
message = "Are you sure you want to upload the counted quantities?\n\nIt may take a few minutes to reflect your changes.";
break;
case "download":
message = "Downloading new worksheets may overwrite existing counted quantities, do you want to continue?\n\n" +
"NOTE: You may want to upload counts first.\n\n" +
"(Changed counted quantities will still be available for upload)";
break;
default:
message = action;
break;
}
alertDialogBuilder.setTitle("WARNING");
alertDialogBuilder.setMessage(message);
DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if(which == DialogInterface.BUTTON_POSITIVE) {
if (action.equals("upload")) {
MainActivity.upload(context);
} else if (action.equals("download")) {
MainActivity.download(context);
}
} else {
dialog.cancel();
}
}
};
alertDialogBuilder.setPositiveButton("YES", listener);
alertDialogBuilder.setNegativeButton("NO", listener);
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
}
任何建议都受到赞赏。我是Android新手。
setView()
是用于对话框主体的,而不是按钮。 - Jeffrey Blattman