要将AlertDialog的背景颜色更改为白色,可以使用以下代码示例:
首先,在styles.xml文件中定义一个新的样式,如下所示:
接下来,在活动的代码中创建AlertDialog时,将样式应用于它,如下所示:
AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.AlertDialogTheme);
builder.setTitle("Title")
.setMessage("Message")
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// 点击确定按钮的逻辑
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// 点击取消按钮的逻辑
}
});
AlertDialog dialog = builder.create();
dialog.show();
在上面的示例中,我们通过将自定义的样式"AlertDialogTheme"传递给AlertDialog.Builder来将白色背景应用于AlertDialog。
上一篇:Androidx.annotation.keep发生了什么,并且有什么新的解决方案?
下一篇:androidx.appcompat.app.AppCompatActivity#closeOptionsMenu不关闭菜单。