要创建不使用Theme.MaterialComponent扩展的Android MaterialAlertDialog,可以按照以下步骤进行操作:
implementation 'com.google.android.material:material:1.5.0'
styles.xml:
AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(context, R.style.AlertDialogTheme));
builder.setTitle("Title")
.setMessage("Message")
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// 响应PositiveButton点击事件
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// 响应NegativeButton点击事件
}
});
AlertDialog dialog = builder.create();
dialog.show();
通过这种方式,你可以使用自定义的样式来创建Android MaterialAlertDialog,而不依赖于Theme.MaterialComponent扩展。你可以根据需要自定义对话框的外观,包括背景、文本颜色和按钮颜色等。