要保持Alert dialog在不同主题下的一致性,可以通过自定义AlertDialog中的按钮布局来解决此问题。
首先,创建一个名为custom_alert_dialog.xml的XML文件,其中定义了自定义对话框的布局和样式,包括按钮的文本颜色、背景等。以下是一个示例:
然后,在需要使用AlertDialog的Activity或Fragment中,使用以下代码创建对话框:
AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.CustomDialogStyle);
View customView = getLayoutInflater().inflate(R.layout.custom_alert_dialog, null);
builder.setView(customView);
ImageView dialogIcon =