Я знаю, что это не тот ответ, который вам нужен, но, как я однажды пытался адаптировать стиль диалогового окна системных предупреждений, я действительно устал пытаться адаптировать стили так, как я хотел, для моего приложения, только для случая, когда вы устали от поиска решения, подумайте над написанием своего настраиваемого диалогового окна оповещения и просто сделайте полный макет самостоятельно: -)
Вот пример простого заголовка, сообщения и двухкнопочного диалога, который вы можете адаптировать (в этом примере используется привязка данных):
public class StyledAlertDialog {
public static class Builder {
private Context context;
private String title;
private String message;
private int resPositiveButton;
private DialogInterface.OnClickListener positiveListener;
private int resNegativeButton;
private DialogInterface.OnClickListener negativeListener;
private boolean cancelable = true;
public Builder(Context context) {
this.context = context;
// default value for cancel button
this.resNegativeButton = R.string.button_cancel;
}
public Builder setTitle(int resTitle) {
this.title = context.getString(resTitle);
return this;
}
public Builder setTitle(String title) {
this.title = title;
return this;
}
public Builder setMessage(int resMessage) {
this.message = context.getString(resMessage);
return this;
}
public Builder setMessage(String message) {
this.message = message;
return this;
}
public Builder setPositiveButton(int resPositiveButton, DialogInterface.OnClickListener positiveListener) {
this.resPositiveButton = resPositiveButton;
this.positiveListener = positiveListener;
return this;
}
public Builder setNegativeButton(int resNegativeButton, DialogInterface.OnClickListener negativeListener) {
this.resNegativeButton = resNegativeButton;
this.negativeListener = negativeListener;
return this;
}
public Builder create() {
return this;
}
public void setCancelable(boolean cancelable) {
this.cancelable = cancelable;
}
public void show() {
final AlertDialog alertDialog = new AlertDialog.Builder(context).create();
LayoutInflater inflater = LayoutInflater.from(context);
// In this special case null is the only valid choice as the root
// of the alertDialog does not exist yet.
View inflatedView = inflater.inflate(R.layout.dialog_styled_layout, null);
DialogStyledLayoutBinding viewBinding = DialogStyledLayoutBinding.bind(inflatedView);
if (title != null && title.length() > 0) {
viewBinding.customDialogTitle.setText(title);
viewBinding.customDialogTitle.setVisibility(View.VISIBLE);
} else {
viewBinding.customDialogTitle.setVisibility(View.GONE);
}
viewBinding.customDialogMessage.setText(message);
viewBinding.customPositiveButton.setText(resPositiveButton);
viewBinding.customPositiveButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
alertDialog.hide();
if (positiveListener != null) {
positiveListener.onClick(alertDialog, 0);
}
}
});
viewBinding.customNegativeButton.setText(resNegativeButton);
viewBinding.customNegativeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
alertDialog.hide();
if (negativeListener != null) {
negativeListener.onClick(alertDialog, 0);
}
}
});
alertDialog.setCancelable(cancelable);
alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
alertDialog.setView(inflatedView, 40, 0, 40, 0);
alertDialog.show();
}
}
}